Rotation changing 'forward'...

I have an object with a move script and a rotate script.

The rotate script makes the ‘player’ rotate to face the direction he is moving in, the problem is that when the object rotates, so does his sense of ‘forward’, and he ends up walking backwards.

I’ve tried changing the ‘tool handles’ to global, but it’s still happening.

How do i rotate the object without affecting the movement direction?

Thanks, Tom.

The ‘tool handles’ (transform gizmo) is only for you, when you place objects in the scene. It has no influence on the objects during runtime.

If you want to move an object in world coordinates, you have to refrain from using local vectors like ‘transform.forward’. Also most functions work in local space by default, and in that case ‘Vector3.forward’ is also in local coordinates. You’d have to specify that you want to use world coordinates.

Examples:

transform.Translate(Vector3.forward * Time.deltaTime);    //translates the object in local forward

transform.Translate(Vector3.forward * Time.deltaTime, Space.World);   //translates the object in world z direction

transform.Translate(transform.forward * Time.deltaTime, Space.World);    //translates the object in local forward

transform.Translate(transform.forward * Time.deltaTime);    //translates the object in local forward, multiplied with the transformation matrix

Nice.

Space.World is a new one to me, i’ll look it up on the script reference!

Thank you very much, i’m sure this will be the solution. You are a very helpful genius :slight_smile: :slight_smile:

Yeah, that seems to have done it :slight_smile: