- Home /
Cube rotates to the left on its own when moving
I was following the brackeys unity tutorial, and the movement script seems to also rotate the cube to the left for unknown reasons. this is the script
using UnityEngine;
public class playerMovement : MonoBehaviour
{
public Rigidbody rb;
public float ForwardForce = 2000f;
// Update is called once per frame
void FixedUpdate()
{
rb.AddForce(0, 0, ForwardForce * Time.deltaTime);
if (Input.GetKey("d"))
{
rb.AddForce(500 * Time.deltaTime, 0, 0 );
}
if (Input.GetKey("a"))
{
rb.AddForce(-500 * Time.deltaTime, 0, 0);
}
}
}
I found a video from an unanswered question which demonstrates the issue.
Answer by MHernandezOlmo · Jul 23, 2020 at 12:04 PM
Hello @weegeemaker, I don't know which tutorial is, but I'm pretty sure you can fix it with this:
Go to the game Object's Rigidbody Component, there you will find a section "Constraints". Open that and check the rotations you dont wan't to be modified.
That way, the cube won't rotate by drag or anything else.
I dont want it to not rotate, I want it to not rotate for no reason
The code is not rotating the cube, so the problem can be some kind of drag, or that the cube is not 100% straight looking forward, or that the force is not applied on the center because the cube is not purely symmetric.
Your answer
![](https://koobas.hobune.stream/wayback/20220613003853im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
How do I stop unwanted rotations? 4 Answers
how to stop a player moving thought the walls in a 2d game 1 Answer
Add force lasting 1 frame (simple script) 1 Answer
Trouble with moving cube when key is pressed 1 Answer
Smooth dashing issues 0 Answers