Advertisement
Guest User

Untitled

a guest
Apr 26th, 2018
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.59 KB | None | 0 0
  1. void Enemy::Update(float timestep)
  2. {
  3. //makes sure that the enemy is always looking at the player
  4.  
  5. Vector3 vector_diff = (lookatPlayer->GetPosition() - m_position); //calculate the vector in the direction of the player from the enemy
  6. vector_diff.Normalize(); //calculate the unit vector in that direction
  7. float rotation = acos(vector_diff.Dot(Vector3(0, 0, 1))); //find the angle of rotation needed using cosine
  8. Vector3 cross = vector_diff.Cross(Vector3(0, 0, 1));
  9.  
  10. if (cross.y > 0) {
  11. m_rotY = -rotation;
  12. }
  13. else if (cross.y <= 0)
  14. {
  15. m_rotY = rotation;
  16. }
  17. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement