x


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 '11 at 08:57 PM

Capt_Paradox gravatar image

Capt_Paradox
1 2 2 2

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

2 answers: sort voted first
more ▼

answered Aug 28 '11 at 09:12 PM

Mortennobel gravatar image

Mortennobel
1.9k 10 15 36

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

Aug 28 '11 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 '11 at 11:38 PM FTheCloud

Awesome; thanks!

Aug 29 '11 at 06:40 PM Capt_Paradox

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

Aug 29 '11 at 08:44 PM aldonaletto

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

Jun 30 '13 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 '13 at 04:11 AM

rasheedqw gravatar image

rasheedqw
3 1 5 9

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

x3208
x182
x56

asked: Aug 28 '11 at 08:57 PM

Seen: 7869 times

Last Updated: Sep 15 '13 at 04:12 AM