S
S
src3032021-07-19 23:25:27
C++ / C#
src303, 2021-07-19 23:25:27

How to make the player rotate in Z?

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class PlayerController : MonoBehaviour
{
    private Rigidbody rb;

    void Start()
    {
    	rb = GetComponent<Rigidbody>();
    }

    void Update()
    {
    	if (Physics.Raycast(transform.position, Vector3.down, GetComponent<BoxCollider>().size.y / 2 + 1f))
    	{
    		Quaternion rot = transform.rotation;
      rot.z = Mathf.Round(rot.z / 95) * 95;
      transform.rotation = rot;
    		if (Input.GetKeyDown(KeyCode.Space)) {
    			rb.velocity = Vector3.zero;
    			rb.AddForce(Vector2.up * 5000);
    		}
    	}
    	else {
    		transform.Rotate(Vector3.back * 5f);
    	}
    }
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vasily Bannikov, 2021-07-20
@vabka

https://stackoverflow.com/questions/28648071/rotat...
https://forum.unity.com/threads/how-to-set-rotatio...
https://stackoverflow.com/questions/57716631/ unity...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question