SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Scripting Help

Reply
 
Thread Tools Display Modes
Old 16/06/2013, 02:14 AM   #1
WillyP
High-roller
 
WillyP's Avatar
 
Join Date: Jul 2010
Location: England
Posts: 2,027
Reputation: 63
Default Calculating vehicle height

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: http://wiki.sa-mp.com/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.
__________________
once average now terrible
WillyP is offline   Reply With Quote
Old 24/06/2013, 01:39 AM   #2
Kar
Banned
 
Join Date: May 2010
Location: Black Asylum
Posts: 2,938
Reputation: 538
Default Re: Calculating vehicle height

GetVehicleModelInfo then z /= 2

thats the height of the vehicle
Kar is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Calculating hex Misiur Scripting Help 1 04/03/2013 05:50 PM
Help calculating FPS Mace Scripting Help 0 28/09/2012 10:02 PM
Which one out of x,y,z is the height jueix Scripting Help 3 28/05/2012 08:44 AM
Getting vehicle height for sirens? acade Help Archive 3 21/12/2010 08:48 PM
height [SF]RobMob Help Archive 4 06/05/2010 01:48 AM


All times are GMT. The time now is 07:56 PM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.