Object orientation remains the same while rotating object
I have a script that rotates my object which works fine, however, even though the object has rotated it maintains its original orientation. To clarify, I mean the object has rotated around its y axis but its x and z axis' are still what they were at the start of the game. If the object is rotated 90 degrees around its y axis and I try to use Vector3.Forward, it will move perpendicular to the way its facing, the direction it was facing at the start. Heres the code I used to rotate:
if (Input.GetKey(KeyCode.D) && sailMode > 0)
{
rigidBody.AddTorque(Vector3.up * rotateSpeed * Time.deltaTime, ForceMode.Force);
}
else if (Input.GetKey(KeyCode.A) && sailMode > 0)
{
rigidBody.AddTorque(Vector3.up * -rotateSpeed * Time.deltaTime, ForceMode.Force);
}
Does anyone know how I can stop unity from doing this?
Answer by HenryStrattonFW · Feb 02, 2017 at 10:20 AM
This is because Vector3.Forward is a world space declaration, no matter what orientation an object in this will be the case, instead of using Vector3.Forward try using the objects transform.forward this forward direction is then relative to the transforms orientation.
Your answer
Follow this Question
Related Questions
Cant stop object/ridgidbody from rotating 2 Answers
Rotate object with 90 degrees? 1 Answer
Rotate player with mouse. 0 Answers
Rotating to a certain degree and stopping? 2 Answers
[Help] Objects rotate wrong when passing from 0 to 360 0 Answers