x


Lock rotation axis?

So I'm rotating an object around a sphere using the below code:

transform.LookAt(target2);

The problem is that I don't want it to rotate along the Z axis, only the X and Y axis. How would I do this?

more ▼

asked Jul 10 '10 at 04:47 PM

ROM gravatar image

ROM
262 46 49 58

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

2 answers: sort voted first

What you want it to do is keep the position of the target's z axis but only transform the x and y axis, like below.

transform.LookAt(Vector3(transform.position.x, transform.position.y, target2.position.z));
more ▼

answered Jul 10 '10 at 04:50 PM

Deikkan gravatar image

Deikkan
198 8 9 19

Oddly it doesn't seem to work. Its for the camera and I don't want it to rotate along the Z axis but that doesn't work basically at all. It doesn't look at the center of the sphere or anything.

Jul 10 '10 at 05:02 PM ROM

you could also try 'transform.eulerAngles.z = 0;' That will make sure that the z rotation is always 0

Jul 10 '10 at 05:35 PM Deikkan

@Deikkan - I think you want to look at Vector3(target.position.x, target.position.y, transform.position.z) to do what you are saying above. ie. project the target point into the horizontal plane containing the camera.

Jul 10 '10 at 11:59 PM cncguy

that transform.eulerAngles.z and x stuff works the best! i highly recommend you try that before you try the above

Aug 17 '11 at 06:32 PM IMTRIGGERHAPPY9
(comments are locked)
10|3000 characters needed characters left

Thank you for this response! Its been a huge help to me.

more ▼

answered Jun 18 '11 at 03:08 AM

chrono1081 gravatar image

chrono1081
84 7 7 11

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

x2171
x1281
x727
x329
x243

asked: Jul 10 '10 at 04:47 PM

Seen: 6903 times

Last Updated: Aug 17 '11 at 06:32 PM