x


How do i make object look at another object only on Y-Axis?

Hello

I have this script

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

but I only want the object to rotate on the Y-Axis can someone help?

more ▼

asked Dec 01 '11 at 10:09 PM

Aydan gravatar image

Aydan
180 28 37 47

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

1 answer: sort voted first

Calculate the direction vector and zero its y component - this makes the direction strictly horizontal:

  var dir = target.position - transform.position;
  dir.y = 0; // kill height differences
  transform.rotation = Quaternion.Slerp(transform.rotation, Quaternion.LookRotation(dir), rotationSpeed * Time.deltaTime);
more ▼

answered Dec 01 '11 at 10:24 PM

aldonaletto gravatar image

aldonaletto
41.2k 16 42 195

awesome works great thanks.

Dec 01 '11 at 10:41 PM Aydan
(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:

x327
x38

asked: Dec 01 '11 at 10:09 PM

Seen: 749 times

Last Updated: Dec 01 '11 at 10:41 PM