Vice City: Multiplayer

Server Development => Scripting and Server Management => Snippet Showroom => Topic started by: PSL on May 29, 2023, 11:18 AM

Title: Player Vertical Angle
Post by: PSL on May 29, 2023, 11:18 AM
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);

    angle=(angle*100).tointeger();
    angle=angle.tofloat()*0.01;
    return angle;
}
Title: Re: Player Vertical Angle
Post by: Sebastian on May 31, 2023, 04:55 AM
Looks promising. Good job!
Would be awesome to have one for cars too