Enemy AI - turn towards player

I have an nme and a player. Both have vector3f locations and a heading. What is the best way to have the nme come up with how much to turn to face player?

Dot product is in there somewhere (I think) but that gives me a very odd number.

This is in 3D.

Thanks a ton!

For normalized vectors, v1.dot(v2) = cos(theta), so theta = acos(v1.dot(v2)). The Vector3f class also supports v1.angle(v2). Note that both vectors must be in the same coordinate frame, but it sounds like they are in your case :slight_smile:

thanks. I failed to mention that the vector3f is a class I wrote to use iwth LWJGL. It has a Dot calc.

I guess I could also try to send a Ray out from my nme and rotate him until he has a collision fo ray and player??

Yes. It would be good to first know the direction that you’re going to turn. Why rotate 270 degrees when you only need to rotate 90? :slight_smile: This can be done by transforming the normalized vector between the player and enemy into the player’s coordinate space and then evaluating the x coordinate of the transformed vector. You can just turn until the dot product between the transformed vector and the local y-axis is arbitratily close to 1.0. Hope this helps!

Thanks for your help. All set now. Now to “tone” down the accuracy of the nme’s LOL

Thanks again.