Adjust a dynamic object POS to a vehicle without attaching - Printable Version
+- SA-MP Forums Archive (
https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (
https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (
https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Adjust a dynamic object POS to a vehicle without attaching (
/showthread.php?tid=610304)
Adjust a dynamic object POS to a vehicle without attaching -
AlexBlack - 22.06.2016
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:vehx, Float:vehy, Float:vehz;
GetVehiclePos(id, vehx,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.
Re: Adjust a dynamic object POS to a vehicle without attaching -
Abagail - 22.06.2016
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);