Object offset to a vehicle
#1

Hey,

I've been looking for a valid solution to get an object's offset to a vehicle but I couldn't find any, at least couldn't find a working one (some of them works but the calculation is not proper).

Do any of you know a way to calculate it or is there a valid include/filterscript that calculates it properly?
Reply
#2

1 - https://sampforum.blast.hk/showthread.php?tid=541980
2-
Код:
stock GetObjectOffset(objectid, vehicleid, &Float: X, &Float: Y, &Float: Z)
{
new Float: pos[3], vpos[3];
GetObjectPos(objectid, pos[0], pos[1], pos[2]);
GetVehiclePos(vehicleid, vpos[0], vpos[1], vpos[2]);
new calcpos[3];
calcpos[0] = pos[0]-vpos[0];
calcpos[1] = pos[1]-vpos[1];
calcpos[2] = pos[2]-vpos[2];
X = calcpos[0];
Y = calcpos[1];
Z = calcpos[2];
return 1;
}
By Abagail
3 - https://sampwiki.blast.hk/wiki/GetVehicleModelInfo
4 - https://sampforum.blast.hk/showthread.php?tid=489229 - it can be helpful as well
Reply
#3

1- The link is broken, I saw it before.
2- This only works when the angle of the vehicle is zero or something like that, it's one of those I stated in my first post which doesn't calculate it properly.
3- I'm aware of this function but I've never tried to calculate offsets using it.
4- These looks way better, I'll give them a shot.

If you have a better idea, feel free to post please!
Reply
#4

Well, seems like we have an include created by Gamer_Z to GetVehicleMatrix and POSITION from VEHICLE OFFSET but that's actually not what I'm looking for.

What I'm looking for is, getting offsets from x, y, z coordinates. Basically, it's for a vehicle-object-attach editor.
Reply
#5

-edit-

Yea, I didn't understand that post.
Reply
#6

Well you need the VehicleMatrix, either use Gamer_Z include or any other which allows you to calculate the direction vectors (forward right up)
I will give you two versions, one with my include "rotation.inc" which does everything step by step and one version with the VehicleMatrix

Both include offer function/s to calculate the position with the given offset but how to get the offsets from the given coordinates?
This is no hidden magic or something, you need to use basic 3d geometry, first you get the offset (world coordinates), than you use the dot product to project this vector on the relative system (right, forward, up / pitch, roll, yaw)

Rotation.inc
PHP код:
//CODE 
Reply
#7

Well, this seems to be working, thanks.

Can't we actually calculate offsetRX, ry, rz? Well, I attach the object to vehicle with object's last rx, ry, rz but they're not correct when it's attached to the vehicle.

- Your include works fine and calculates offsetx, y, z properly, what about rx, ry and rz?
Reply
#8

Sure we can, I put these function inside the include and renamed them

Quote:
Originally Posted by Nero_3D
Посмотреть сообщение
Added GetVehicleObjectPositionOffset / GetVehicleObjectPositionWorld to calculate the position and rotation from a normal object to an attached object / vice versa

PHP код:
GetVehicleObjectPositionWorld(vehicleidFloatatt_XFloatatt_YFloatatt_ZFloatatt_rotXFloatatt_rotYFloatatt_rotZ, &FloatX, &FloatY, &FloatZ, &FloatrotX, &FloatrotY, &FloatrotZ)
GetVehicleObjectPositionOffset(vehicleidFloatXFloatYFloatZFloatrotXFloatrotYFloatrotZ, &Floatatt_X, &Floatatt_Y, &Floatatt_Z, &Floatatt_rotX, &Floatatt_rotY, &Floatatt_rotZ
Well, I didn't intend to add functions for special cases but putting these in the example section would be copy and paste
Reply
#9

Thanks a lot!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)