World position from vehicle offset
#1

Yoo, I was wondering on how I would get the position of the offset of a vehicle in world values. For example, I'd use https://sampwiki.blast.hk/wiki/GetVehicleModelInfo to get the position of the fuel cap. However when this is done and I want to get the coordinates, and all it returns is 0 as I only use the GetVehicleModelInfo function in order to retrieve values. I then began a search to see if anyone had the solution, and I came across a post where something about trigonometry was mentioned. Trigonometry will be used to calculate the world position from a vehicle position (and offset) which will return the value of the fuel cap, or any example you wish to use. I have no idea how to do trigonometry in association with coding as that's not the kind of thing I get taught in math class. If someone could create a function for me or explain how to then it would be greatly appreciated
Reply
#2

Not sure, but is this what your looking for: http://forum.sa-mp.com/showthread.ph...76#post2580576
Reply
#3

I already had a similar function however I will try yours and compare results
Reply
#4

pawn Code:
CMD:wheelpos(playerid,params[])
{
    new str[128],str2[128],str3[128];

    new Float:x,Float:y,Float:z,Float:a;

    new Float:vx,Float:vy,Float:vz;
   
    new Float:rx,Float:ry,Float:rz;
   
    new Float:nx,Float:ny,Float:nz,str4[128];
   
    GetVehiclePos(GetPlayerVehicleID(playerid),x,y,z);
    GetVehicleZAngle(GetPlayerVehicleID(playerid),a);
    GetVehicleModelInfo(GetPlayerVehicleID(playerid),VEHICLE_MODEL_INFO_WHEELSFRONT,vx,vy,vz);
    GetVehiclePosEx(GetPlayerVehicleID(playerid),vx,vy,vz,0.1,0.1,0.1);
   
    nx = vx-x;
    ny = vy-y;
    nz = vz-z;
    GetVehicleRelativePos(GetPlayerVehicleID(playerid),rx,ry,rz,0.1,0.1,0.1);

    format(str,128,"x = %f y = %f z = %f",x,y,z);
    format(str2,128,"wheelinfo: x = %f y = %f z = %f",vx,vy,vz);
    format(str3,128,"relative pos: x = %f y = %f z = %f - unused",rx,ry,rz);
    format(str4,128,"difference x = %f y = %f z = %f",nx,ny,nz);

    SendClientMessage(playerid,-1,str);
    SendClientMessage(playerid,-1,str2);
    SendClientMessage(playerid,-1,str3);
    SendClientMessage(playerid,-1,str4);
    //other stuff
    return 1;
}
Here's part of what I've been doing, however I just want to return the location of the front wheels however I believe what I have done is slightly wrong..
Reply
#5

Idk what you're doing, but I noticed one mistake:
Code:
GetVehicleModelInfo(GetPlayerVehicleID(playerid),VEHICLE_MODEL_INFO_WHEELSFRONT,vx,vy,vz);
You need to pass the model ID, not the vehicle ID
Reply
#6

Quote:
Originally Posted by Stylock
View Post
Idk what you're doing, but I noticed one mistake:
Code:
GetVehicleModelInfo(GetPlayerVehicleID(playerid),VEHICLE_MODEL_INFO_WHEELSFRONT,vx,vy,vz);
You need to pass the model ID, not the vehicle ID
Ahh, silly mistake. What I'm trying to do is get the offset values, and return it in the world x,y,z. So as a test I could create an object where the values I get from the offset info, then do some extra changing around.

So, vehicle pos+vehicle offset = object and world value. The object will be created at the coordinates from the offset values
Reply
#7

That's what the function I posted does. You need to pass the petrol cap's offsets to the function and it will calculate the wolrd coordinates.
Reply
#8

I need something so that it stores the value until it has been removed. I used objects however obviously when the vehicle moved they didn't stick. Basically getting the offset position and saving it to the vehicle, probably using a timer to keep it updated. P.S: I don't actually want the fuel cap, I lied

EDIT: I have it working now, thanks for all your help!
Reply


Forum Jump:


Users browsing this thread: 5 Guest(s)