- Home /
Why does my cube rotate?
I am using this script
var power : int;
function FixedUpdate () {
if(Input.GetButton("Forward"))
rigidbody.AddTorque(transform.forward * power);
if(Input.GetButton("Backward"))
rigidbody.AddTorque(-transform.forward * power);
if(Input.GetButtonDown("Left"))
transform.eulerAngles += Vector3(0,-90,0);
if(Input.GetButtonDown("Right"))
transform.eulerAngles += Vector3(0,90,0);
}
When pressing A or D (left/right) the cube will rotate 90 degrees in that direction as intended, but if you hold the button down it is like torque is being added to the cube, exactly like pressing W or S (forward/backward)
Like executing
rigidbody.AddTorque(transform.forward * power);
Does anyone have any ideas as to why this is happening?
Edit - forgot to add i'm an utter noob. I've only been learning unity/javascript a few days but it's not my first language/engine
Edit 2 - i should note that when pressing both a and d has the same effect as pressing w, not s
Edit 3 - nevermind, i had a and d set as alternate inputs to forward. Doh!
Your answer
![](https://koobas.hobune.stream/wayback/20220613100556im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Show "Score:5" on my screen, how? 1 Answer
Realistic Bouncing Effect 1 Answer
Time.timescale cause extreme lag? 1 Answer
Faux Gravity Prolem? #2 2 Answers
Deactivating a power up script after a certain amount of time 1 Answer