How to get the side coordinates of vehicle?
#1

How to get a vehicle's side coordinates. I cannot use GetPlayerVehiclePos and then Setting the player's pos to +x's of the vehicle's, because the vehicle keeps moving and taking turns, so the x, and y pos of the vehicle keeps rotating. I want to know a solution to get the vehicle's side position.
Reply
#2

Not exactly sure what you mean by this, but you might try something like:

Код:
SetPlayerPos(playerid,xvarible+1,yvarible,zvarible);
Just keep trying diffirent settings like this and see if that resolves your issue
Reply
#3

Not sure what u mean but

pawn Код:
new Float:vehx, Float:vehy, Float:vehz;
GetVehiclePos(1, vehx, vehy, vehz); // Vehicle ID, Variable to store the X, Y, Z Coords..

SetPlayerPos(playerid,vehx+2,vehy+2,vehz);
So you just use +
Reply
#4

I just want to get a vehicle's side(door part) coordinates. The code given above will not always spawn me to the side of the vehicle as the car's rotation will keep changing as the player drives, it may spawn me forth or back of the car.
Reply
#5

Thats a job for ye olde trigonometrye, just some floatsin and floatcos:

pawn Код:
new Float:rot, Float:x, Float:y, Float:z;
    GetVehicleZAngle(targetid, rot);
    rot = 360 - rot;    // Making the vehicle rotation compatible with pawns sin/cos
    GetVehiclePos(vehicleid, x, y, z);
    x = floatsin(rot,degrees) * yoff + floatcos(rot,degrees) * xoff + x;
    y = floatcos(rot,degrees) * yoff - floatsin(rot,degrees) * xoff + y;
    z = zoff + z;

    /*
       where xoff/yoff/zoff are the offsets relative to the vehicle
       x/y/z then are the coordinates of the point with the given offset to the vehicle
       xoff = 1.0 would e.g. point to the right side of the vehicle, -1.0 to the left, etc.
    */
Should be exactly what you need, hope this helps.
Reply
#6

Thanks alot Mauzen, your always helping me around.
You forgot to define 'tz'. I tried working on this, but it's very hard for me. If you could give me a example of how to work this, it would be really appreciative.
Reply
#7

Quote:
Originally Posted by ||123||
Посмотреть сообщение
Thanks alot Mauzen, your always helping me around.
You forgot to define 'tz'. I tried working on this, but it's very hard for me. If you could give me a example of how to work this, it would be really appreciative.
Once you've implemented his code, just set their position to X, Y, and Z, and you should be next to the vehicle. (assuming his math is correct, which it looks as if it is - I'm no mathematician)
Reply
#8

Oh right, tz should have been z, just corrected it.
What this does is in short rotating the coordinate system. I might sound a bit complicated, but just because I suck at explaining things, basically it is very simple
To explain it, imagine the vehicle is facing exactly north with 0.0° rotation, and its position is stored in x/y/z. If you now increase x (x+1/y/z), youll get a point that is on the right side of the car, near its right door, of course. Reducing it (x-1/y/z) will return a point to its left side. The same about changing y, if you increase it a bit youll get coordinates near the vehicles hood.
Now imagine the vehicle turns by 180°, so its trunk faces to north and the hood to south. If you now increase x youll get a point near the vehicles left side of course, and not the right side. If you just rotate the vehicle by 90° increasing x will even point to the hood of the car. (you already got that in your first post, but maybe this helps others to get the situation)

Using that code, to get a point near the right side of the vehicle you dont just increase x, but you increase the x offset (xoff). E.g. xoff=1 means "give me the position that is 1m to the right side of the vehicle", or yoff=-1 always gives the point that is 1m behind the vehicle, no matter what direction it faces.
zoff is quite useless here, as it just increases the z coordinate, which isnt affected by the rotation of the vehicle anyways.

I made a ready-to-use function from the code, that can be used like GetVehiclePos, but you can specify the offsets i described before.

pawn Код:
stock GetVehicleRelativePos(vehicleid, &Float:x, &Float:y, &Float:z, Float:xoff=0.0, Float:yoff=0.0, Float:zoff=0.0)
{
    new Float:rot;
    GetVehicleZAngle(targetid, rot);
    rot = 360 - rot;    // Making the vehicle rotation compatible with pawns sin/cos
    GetVehiclePos(vehicleid, x, y, z);
    x = floatsin(rot,degrees) * yoff + floatcos(rot,degrees) * xoff + x;
    y = floatcos(rot,degrees) * yoff - floatsin(rot,degrees) * xoff + y;
    z = zoff + z;

    /*
       where xoff/yoff/zoff are the offsets relative to the vehicle
       x/y/z then are the coordinates of the point with the given offset to the vehicle
       xoff = 1.0 would e.g. point to the right side of the vehicle, -1.0 to the left, etc.
    */

}

//Examples:
GetVehicleRelativePos(vehicleid, x, y, z, 1.0, 1.0, 0.0);
    // xoff = 1 -> go 1m to the right side of the vehicle
    // yoff = 1 -> go 1m to the front of the vehicle
    // so this would return about the coordinates of the the front right tire of the car

GetVehicleRelativePos(vehicleid, x, y, z, 0.0, -3.0, 0.0);
    // xoff = 0 -> no change, stay between the driver and passenger seat
    // yoff = -3.0 -> go 3m back to the vehicle
    // so this would return the coordinates near the trunk of the vehicle
So this is a mighty function once you got how it works, as you can get all these coordinates no matter where the vehicle faces.

(Ouch, long text)
Reply
#9

Thanks alot bro.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)