x


Set rotation of a transform

Hi all!

I want to rotate a transform to a specific angle, not add to the existing rotation. Currently, on every frame, I am doing:

transform.Rotate(Vector3.up * rotation);

What I expect is a smooth transition over time as "rotation" changes, however the object is spinning like crazy!

Do I need to use a method to grab the current rotation and then offset by that? Or is there a method that will allow me to directly set the rotation?

Thanks!

more ▼

asked Jan 21 '12 at 07:41 PM

Vesuvian gravatar image

Vesuvian
16 4 5 7

You should use Time.deltaTime, since that line of code is not framerate-independent and will vary as the framerate varies.

Jan 21 '12 at 08:01 PM Eric5h5

I know what I'm doing with the angle itself, my question is about how to set the absolute rotation of the object, not just adjust the rotation.

Jan 21 '12 at 08:40 PM Vesuvian

Transform.eulerAngles?

Jan 21 '12 at 08:46 PM Eric5h5

Thank you! Works perfectly.

Jan 21 '12 at 08:56 PM Vesuvian
(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

transform.localEulerAngles = new Vector3(x,y,z);

more ▼

answered Jan 21 '12 at 11:37 PM

bbrode gravatar image

bbrode
31 4 5 7

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

x2156
x1274
x721

asked: Jan 21 '12 at 07:41 PM

Seen: 2414 times

Last Updated: Jan 21 '12 at 11:37 PM