x


rotate on the Y axis

hello i have an enemy that looks at me and chases me and stuff but it rotates on all the axis to look at me so how do i make it rotate on only the Y axis to look at me? Heres what i've got at the moment.

transform.rotation = Quaternion.Slerp(transform.rotation, Quaternion.LookRotation(target.position - transform.position),rotationSpeed * Time.deltaTime);

Thanks.

more ▼

asked Apr 27 '11 at 02:40 AM

Aydan gravatar image

Aydan
180 28 37 47

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

1 answer: sort voted first

create the rotation vector like this.

rotationVector = target.position - transform.position;
rotationVector.y = transform.position.y;

then pass this to Slerp.

more ▼

answered Apr 27 '11 at 02:45 AM

Ashkan_gc gravatar image

Ashkan_gc
9.1k 33 56 117

how would i put this into the script?

Apr 27 '11 at 03:11 AM Aydan

instead of target.position - transform.position put rotationVector in your LookAt function. that subtraction creates a vector from you toward the target but you should change the y as you see.

Apr 27 '11 at 06:59 AM Ashkan_gc
(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:

x2163
x1279
x804
x329

asked: Apr 27 '11 at 02:40 AM

Seen: 1314 times

Last Updated: Apr 27 '11 at 02:40 AM