Sign in to follow this  
Prog101

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

Recommended Posts

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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this