Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void Enemy::Update(float timestep)
- {
- //makes sure that the enemy is always looking at the player
- Vector3 vector_diff = (lookatPlayer->GetPosition() - m_position); //calculate the vector in the direction of the player from the enemy
- vector_diff.Normalize(); //calculate the unit vector in that direction
- float rotation = acos(vector_diff.Dot(Vector3(0, 0, 1))); //find the angle of rotation needed using cosine
- Vector3 cross = vector_diff.Cross(Vector3(0, 0, 1));
- if (cross.y > 0) {
- m_rotY = -rotation;
- }
- else if (cross.y <= 0)
- {
- m_rotY = rotation;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement