Having one entity look at another.


29-04-2010 03:31:35

Hi, suppose I had two entities, both ninjas. I want one ninja (N1) to look at the other ninja (n2) so that n1 is always facing towards n2. If n2 was to walk around n1, n1 would have done one complete rotation in place. I hope that made sense.

anyway, I was using n1Node.LookAt(n2Node.Position, Node.TransformSpace.TS_LOCAL), but it was causing n1 to do some really weird things, like cart wheels.

Any suggestions? Help would be greatly appreciated.


29-04-2010 04:11:31

n1Node.SetAutoTracking(true, n2Node);


29-04-2010 14:52:11

You sir, are a gentleman and a scholar. I can't believe I forgot about that. Thank you!


01-05-2010 05:47:42

Firstly, I apologize for double posting, but I'm not sure if editing would register the thread as having a new post...

Anyway, one more question (so I hope) in regards to this. Suppose n2 was to jump, and I didn't want n1 to look up after him. Is there any way to prevent n1 from looking up (so that his pitch never changes)?


01-05-2010 12:25:13

Instead of auto tracking:
Vector3 lookAtVec = n2Node.Position;
lookAtVec.y = n1Node.Position.y;
n1Node.LookAt(lookAtVec, Node.TransformSpace.TS_WORLD);