How do i stop cube from rotating while moving?

Hello everyone, i have managed to make my cube move with WASD and Space to jump but when it does move my cube like to flip and rotate, i don’t want that to happen. How would i stop him from doing that?

using UnityEngine;

public class playermovement : MonoBehaviour
{

    public Rigidbody rb;
    public float forwardForce = 50f;

    // Use this for initialization
    private void Start()
    {
        Debug.Log("hello world");
        rb = GetComponent<Rigidbody>();
     
    }

     private void FixedUpdate()
    {
        if (Input.GetKey(KeyCode.A))
            rb.AddForce(Vector3.left * forwardForce);
        if (Input.GetKey(KeyCode.D))
            rb.AddForce(Vector3.right * forwardForce);
        if (Input.GetKey(KeyCode.W))
            rb.AddForce(Vector3.forward * forwardForce);
        if (Input.GetKey(KeyCode.S))
            rb.AddForce(Vector3.back * forwardForce);
        if (Input.GetKey(KeyCode.Space))
            rb.AddForce(Vector3.up * forwardForce);
          
       
      

    }
}

You must maybe consider to use transform.LocalEulerAngles in stead of AddForce. That will give you a more instant stop of rotation. You can also mess around with the rotational drag property of the rigidbody.

1 Like

Rigidbody setting in the inspector → constranits → rotation (x,y,z)

4 Likes

your A SUPER SAIYAN GOD.

YOUR A SUPER SAIYAN GOD

oh, yes, I know…

1 Like