Advertisement
Guest User

PlayerLook

a guest
Aug 28th, 2014
193
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.60 KB | None | 0 0
  1. //Makes the given player look at the given position.
  2. function PlayerLook(player, targetPos)
  3. {
  4. if(player != null && player.IsValid())
  5. {
  6. local eyePos = player.EyePosition();
  7. local eyeToTarget = targetPos - eyePos;
  8.  
  9. local ToDegrees = 180.0 / 3.14159; //Converts radians to degrees (SetAngles uses degrees, atan2 returns radians).
  10.  
  11. local pitch = atan2(eyeToTarget.Length2D(), eyeToTarget.z) * ToDegrees; //Calculate the pitch (up/down) angle.
  12. local yaw = atan2(eyeToTarget.y, eyeToTarget.x) * ToDegrees - 90.0; //Calculate the yaw (left/right) angle.
  13.  
  14. player.SetAngles(pitch,yaw,0);
  15. }
  16. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement