Answer the question
In order to leave comments, you need to log in
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
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 questionAsk a Question
731 491 924 answers to any question