Guys, I spawned an enemy that moves towards me all the time no matter where I move.

Now I need to somehow rotate properly the enemyRun animation so the enemy faces ME all the time, no matter where I move.

Sounds easy, but that glm::rotate function is unbelievably messed up ( at least for me ).

What my logic is:

1.Find the vector pointing from 'enemyPosition' to 'playerPosition' and normalize it. Lets call that vector 'movementDirection'.

2.Now find the vector that shows the current direction that the enemy faces. When my enemy is spawned, I made it to face the +X axis by default.

3. Then find the angle between the current direction the enemy faces( along +X ) and the direction the enemy needs to face ( towards me ) and somehow regulate it to rotate somehow. ( this is the part where I don't know what I'm doing )

Update 1: The glm::rotate function accepts radians not degrees, this means that rotation.w should be in radians, so glm::radians( angle ).

Update 2: Dot product doesn't work for 360 degrees, just for 180, I need more vectors to cleary distinguish the position in a 360-degree environment.

Update 3. In order to get the 360 degrees I need a third vector, lets say I can get the third vector using a cross product, but then how to use the third one properly?

The movement is ok, but the rotation is messed up. Here is the code:

Note: rotation.w is the rotationAngle, rotation.y = 1.0f means: rotate along the Y axis.

void Enemy::moveTowardsPlayer( glm::vec3 playerPos ) { movementDirection = normalize( playerPos - position ); rotation.w = dot( movementDirection, faceDirection )*someNumberIdontKnow; //This is the rotation angle rotation.y = 1.0f; position += movementDirection/50.0f; }

**Edited by Heelp, 22 July 2016 - 10:57 AM.**