- Home /
an object rolls forward and turn right at the same time...
I am trying to do that with this code.
void Update () {
if (Input.GetKey(KeyCode.LeftArrow)) {
transform.Rotate(Vector3.down 36 Time.deltaTime, Space.Self);
}
if (Input.GetKey(KeyCode.RightArrow)) {
transform.Rotate(Vector3.up 36 Time.deltaTime, Space.Self); }
}
void FixedUpdate() {
transform.rigidbody.AddTorque(Vector3.right * 0.5f);
}
The object keeps rolling and no turning. Any advice will be so appreciated. Thanks in advance.
Answer by Tekksin · Jun 14, 2014 at 08:15 AM
my first bit of advice would be to put your inputs in the fixed update, since they are controlling the rigidbody you're effecting, and see if that fixes things for you. But you need to explain your question a little better. The title infers what you want or what's happening? I'm assuming you want it to rotate to the right gradually? We also have no idea what your vars do.
http://unity3d.com/learn/tutorials/modules/beginner/physics/addtorque
You might find that link useful. Notice that the inputs are in fixed update.
Your answer