x


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.

more ▼

asked Jul 16 '12 at 04:08 PM

Tea_Doogun gravatar image

Tea_Doogun
78 4 12 22

(comments are locked)
10|3000 characters needed characters left

3 answers: sort voted first

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
more ▼

answered Jul 16 '12 at 04:18 PM

Piflik gravatar image

Piflik
5.4k 15 26 44

(comments are locked)
10|3000 characters needed characters left

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 :) :)

more ▼

answered Jul 16 '12 at 05:04 PM

Tea_Doogun gravatar image

Tea_Doogun
78 4 12 22

(comments are locked)
10|3000 characters needed characters left

Yeah, that seems to have done it :)

more ▼

answered Jul 16 '12 at 05:04 PM

Tea_Doogun gravatar image

Tea_Doogun
78 4 12 22

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x2172
x727

asked: Jul 16 '12 at 04:08 PM

Seen: 334 times

Last Updated: Jul 16 '12 at 05:04 PM