Calculating vehicle height
#1

Hey, I've been having some problems with getting a vehicle height, storing it and creating an object with the Z value being the height of the vehicle. So far I have used GetVehicleModelInfo, and GetVehicleRelativePos. They both failed to work for me, as I must have gone wrong somewhere.

Here's the GetVehicleRelativePos function

pawn Code:
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(vehicleid, 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.
    */

    return 1;
}
And the wiki page for GetVehicleModelInfo: https://sampwiki.blast.hk/wiki/GetVehicleModelInfo

And the testing command:

pawn Code:
CMD:test(playerid,params[])
{
    new veh,obj,
    Float:x,
    Float:y,
    Float:z,
    Float:ox,
    Float:oy,
    Float:oz,
    string[64];
    veh = GetNearestVehicle(playerid,15);
    GetVehiclePos(veh,x,y,z);
    //GetVehicleRelativePos(veh,ox,oy,oz,0,0,1.0);
    GetVehicleModelInfo(GetVehicleModel(veh),VEHICLE_MODEL_INFO_SIZE,ox,oy,oz);
    obj = CreateObject(18646,x,y,z,-1,0,0,0);//or ox,oy,oz
    AttachObjectToVehicle(obj,veh,x,y,z,0,0,0);//or ox,oy,oz
    format(string,sizeof(string),"vehicle is %.1fm wide, %.1fm long and %.1fm high",ox,oy,oz);
    SendClientMessage(playerid,-1,string);
    return 1;
}
What I want this to do is store the value from GetVehicleModelInfo or GetVehicleRelativePos and create the object exactly on the top of the roof, without it being too high or too low, I'm pretty tired so I'm not going to keep trying with this and hopefully fresh eyes will point out my mistakes.
Reply
#2

GetVehicleModelInfo then z /= 2

thats the height of the vehicle
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)