Making an Object Rotate to Face Another Object

Alright. So, in the project I'm working on, I have an object that I want to turn to face another object. Simply put: how. Although it seems like a good option, I can't get transform variables to work. Also, for extra credit, can I make it reference a different object (with the same name) in each scene? Alternatively, the objects being rotated towards are immobile, so making the object rotate towards a given point would work as well. Thanks!

more ▼

asked Aug 28, 2011 at 08:57 PM

avatar image

1 4 4 5

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

2 answers: sort voted first
more ▼

answered Aug 28, 2011 at 09:12 PM

avatar image

1.9k 25 30 55

Alright, thanks. Is there a way to do this and make the rotation only occur about the z-axis?

Aug 28, 2011 at 10:00 PM Capt_Paradox

Add a rigidbody to your object and check off freeze rotation under Constraints for x or y.

Aug 28, 2011 at 11:38 PM FTheCloud

Awesome; thanks!

Aug 29, 2011 at 06:40 PM Capt_Paradox

@FTheCloud, this won't work: rigidbody constraints only affect physics.

Aug 29, 2011 at 08:44 PM aldonaletto

I'm having a similar problem. I want it to only rotate on the Y-axis.

Jun 30, 2013 at 12:28 PM Daphoeno
(comments are locked)
10|3000 characters needed characters left
 var damping:int=2;
 var target:Transform;
 var lookPos = target.position - transform.position;
   lookPos.y = 0;
   var rotation = Quaternion.LookRotation(lookPos);
   transform.rotation = Quaternion.Slerp(transform.rotation, rotation, Time.deltaTime * damping); 

someone else came up with the code but it worked for me

more ▼

answered Sep 15, 2013 at 04:11 AM

avatar image

5 12 18 43

(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



Answers and Comments



asked: Aug 28, 2011 at 08:57 PM

Seen: 15653 times

Last Updated: Sep 15, 2013 at 04:12 AM