Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Makes the given player look at the given position.
- function PlayerLook(player, targetPos)
- {
- if(player != null && player.IsValid())
- {
- local eyePos = player.EyePosition();
- local eyeToTarget = targetPos - eyePos;
- local ToDegrees = 180.0 / 3.14159; //Converts radians to degrees (SetAngles uses degrees, atan2 returns radians).
- local pitch = atan2(eyeToTarget.Length2D(), eyeToTarget.z) * ToDegrees; //Calculate the pitch (up/down) angle.
- local yaw = atan2(eyeToTarget.y, eyeToTarget.x) * ToDegrees - 90.0; //Calculate the yaw (left/right) angle.
- player.SetAngles(pitch,yaw,0);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement