Mathy questions.
#1

Straight to the point. I have an 'extra seat' script so players can enter full vehicles. If they press G they spectate the vehicle. When they press ENTER (exit key) they re-spawn behind the vehicle. What I want is so if you press G in front of the vehicle, when you exit you spawn in-front of it again. If I press it next to the driver's door, when I exit I want to appear there, even if the vehicle has moved and turned. In relation to the vehicle's position and angle.

Could someone show me how please? Thank you. Remember, it needs to be in relation to the vehicle, not the map's X/Y/Z axis.
Reply
#2

You could try this:

Make global floats and the id for the vehicle for max players.
Then, when the player presses they key to enter the vehicle, calculate like this:

pawn Код:
for(new vehicleid=0;vehicleid<MAX_VEHICLES;vehicleid++)
{
GetPlayerPos(playerid, x1, y1, z1);
if(IsVehicleInRangeOfPoint(playerid, ~1.0, x1, y1, z1);
{
GetVehiclePos(vehicleid, x2, y2, z2);

x3=x1-x2;
y3=y1-y2;
z3=z1-z2;
}

//When the player wants to exit:

GetVehicle(vehicleid, x2, y2, z2);
SetPlayerPos(playerid, x2-x3, y2-y3, z2-z3);



stock IsVehicleInRangeOfPoint(vehicleid, Float:radi, Float:x, Float:y, Float:z)
{
    new Float:oldposx, Float:oldposy, Float:oldposz;
    new Float:tempposx, Float:tempposy, Float:tempposz;
    GetVehiclePos(vehicleid, oldposx, oldposy, oldposz);
    tempposx = (oldposx -x);
    tempposy = (oldposy -y);
    tempposz = (oldposz -z);
    if (((tempposx < radi) && (tempposx > -radi)) && ((tempposy < radi) && (tempposy > -radi)) && ((tempposz < radi) && (tempposz > -radi)))
    {
        return 1;
    }
    return 0;
}
Reply
#3

mmh.. first, you need the atan2 function for calculating the angle from the position offset (carposition-playerposition) on the x-y axis only (player to vehicle, so that a player pressing G infront of a car, returns an angle of 0.0, behind the car 180.0 etc), then at exiting the car, the "old" angle combined with floatsin/floatcos to respawn the player in relation to the vehicle, should work.

ah, i found this:
pawn Код:
stock Float:AngleBetweenPoints(Float:XA, Float:YA, Float:XB, Float:YB)
{
    //  new Float:Angle=180-(-90+(atan2(YA-YB,XA-XB)));// * 180.0 / 3.141592653;
    new Float:Angle=-(90+(atan2(YA-YB,XA-XB)));// * 180.0 / 3.141592653;
    return Angle;
}
..this stock got edited to work in my object editor, so you may need to change those "90 degrees" for usage with a player instead of another object: the rotations for players/cars/objects are different, idk which will work for you. i kept the 1 commemted line intanct, i hope it helps a bit...

heres the usage for sinus/cosinus:
pawn Код:
newX=vehicleX+(Radius*floatsin(Angle,degrees));
newY=vehicleY+(Radius*floatcos(Angle,degrees));
oops, the newZ should be the same height as the vehicle indeed. almost forgot that ^^
Reply
#4

Could to give me a working example because I have no idea how to implement it. Thanks.
Plus does yours even take in to account their position or just does it as an angle?
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)