Adjust a dynamic object POS to a vehicle without attaching
#1

Well, today i'am trying to make something to attach a object to a vehicle, without using AttachObjectToVehicle, i mean i create a dynamic object and i create a vehicle i want to use EditDynamicObject to adjust the right position in the vehicle, when i confirm, the object will be attached, i believe that have a kind of maths but i'am not sure about my informations, so i try that :


PHP код:
// OnPlayerEditDynamicObject
            
if(pInfo[playerid][pVehicleAttachEdit] != -1) {
                new 
id pInfo[playerid][pVehicleAttachEdit],
                    
Float:vehxFloat:vehyFloat:vehz;
                
GetVehiclePos(idvehx,vehy,vehz);
                
                
VehicleData[id][VehAttachX] = x-vehx;
                
VehicleData[id][VehAttachY] = y-vehy;
                
VehicleData[id][VehAttachZ] = z-vehz;
                
VehicleData[id][VehAttachRX] = rx;
                
VehicleData[id][VehAttachRY] = ry;
                
VehicleData[id][VehAttachRZ] = rz;
                
                
ModVehicle(id);
                
SaveVehicle(id);
                
pInfo[playerid][pVehicleAttachEdit] = -1;
            } 
But the position is still wrong i don't know why, when i make my object in the back of the vehicle, the object will be attached in the front, i need to get the correct way to calcul that.
Reply
#2

You can calculate the offset of an object to a vehicle(assuming you already know where you want the object placed) by subtracting the larger offset with the smaller one.

Example(vx, vy, and vz are the offsets):
pawn Код:
new Float: x, Float: y, Float: z, Float: vx, Float: vy, Float: vz;
GetObjectPos(objectid, x, y, z);
GetVehiclePos(vehicleid, vx, vy, vz);

vx = (x > vx) ? (x) : (vx);
vy= (y > vy) ? (y) : (vy);
vz = (z > vz) ? (z) : (vz);
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)