Jump to content
  • Advertisement
Sign in to follow this  
Prog101

Getting an object to turn and face the enemy in 3D

This topic is 4576 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I Have a 3D Enemy that is tracking the Player and moving towards him, but i want the Enemy to be able to rotate to face the Player while chasing, any Sugestions?

Share this post


Link to post
Share on other sites
Advertisement
You could try rotating the enemy's orientation matrix around the vector which is the normalised cross product of the enemies facing vector with the seperation vector between player and enemy. This should get him rotating in the right direction and the amount of rotation each frame you can take either as the enemy's current rotation speed or the angle between the two vector's you crossed above, which ever is least. You could even modify the rotation speed each frame as a function of angle remaining to get a smoother looking motion.

Share this post


Link to post
Share on other sites
Like Motorherp said, get the axis to rotate about as:
axisVec = (playerPos - enemyPos) x enemyDir

The amount to rotate can then be found as:
angle = acos((playerPos - enemyPos) . enemyDir)

(...assuming the vectors are normalized)
And yeah, interpolate the angle for smooth animation. :)

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!