Player Vertical Angle

Started by PSL, May 29, 2023, 11:18 AM

Previous topic - Next topic


This client function returns the player's horizontal and vertical angles.
It is used as GetAngle("x"); , returns the same value as player.Angle, and a GetAngle("y"); ", returns the player's vertical Angle. One drawback is that when the player is facing in a positive east-west direction, it is impossible to calculate.

function GetAngle(m)
    local angle;
    local a=GUI.ScreenPosToWorld(Vector(GUI.GetScreenSize().X/2,GUI.GetScreenSize().Y/2,1));
    local b=GUI.ScreenPosToWorld(Vector(GUI.GetScreenSize().X/2,GUI.GetScreenSize().Y/2,-1));

    if(m=="x") angle=-atan2(a.X-b.X,a.Y-b.Y);
    if(m=="y") angle=-atan2(b.Y-a.Y,a.Z-b.Z);

    return angle;


Looks promising. Good job!
Would be awesome to have one for cars too


Quote from: Sebastian on May 31, 2023, 04:55 AMWould be awesome to have one for cars too
You have car position and player position on clientside, if its not equal (as on bikes) then you can calculate angle based on those two points, but each car model with its own seats location relative center of car needs specific offset.
...::: vice city :::...