- Home /
Vector3 and AddRelativeTorque
Hi,
I am new to Unity and I was looking at a tutorial online on how to make a ball roll left and right. I know that Vector3.back means (0,0,-1) where -1 is in the Z axis. This code works, but it moves the ball in the X axis.
rigidbody.AddRelativeTorque(Vector3.back * rotation);
Coul somebody please explain me how is this working? Thanks!
When you apply torque to an object it will rotate about the axis that you have defined, which i'm sure you already know. Think of it like this, the z axis travels from the front centre of the object to the back centre of the object, so applying torque to the z axis of the object would force it to spin around this invisible point, like an airplane propeller. Doing it on the x axis would make the object roll forwards like a wheel because the line runs from the centre of the object, left to right.
That makes a lot more sense!!!! Thanks!!! But why is that I need z = -1? The positive x axis is on the right, but a negative torque makes the object rotate to the right. A positive torque makes it rotate to the left. Thus it seems to me that it is reversed. Negative torque makes the x position more positive. A positive torque makes the x position more negative. I mean, it works correctly! I just want to understand it better. Than you very much!!
Answer by yorgaraz · Jun 07, 2014 at 11:48 PM
It is moving at the X axis is because the assumed Z axis is actually relative to the object that it is in joint/child of another object that is X axis globally.
In order for this to work globally, you have to change it to: rigidbody.AddTorque(Vector3.back * rotation);
or you could also click on to switch the unity's scene editor axis presentation from global to local and vice versa.
You also might want to have a look at PositioningGameObjects page.
Could you check at my comment above? Aren't the controls reversed?
Your answer
Follow this Question
Related Questions
How to Spherecast/Raycast diagonally? 1 Answer
Whats the best way to get the Distance between two Vector3? 2 Answers
How can I rotate a vector direction around an arbitrary axis? 0 Answers
make enemy only follow along the X and Z axis 1 Answer
Are there more options to rotation 'Space' relativity? 1 Answer