Attach object to vehicle (Maths problem, not scripting) -
Siralos - 11.09.2012
Hi!
I wrote a code that creates and object and edit it; then find the final position and the final position of a car, and subtstract these values in order to find the relative position of the object from the vehicle, so I can use these values in AttachObjectToVehicle.
When the vehicle is pointing north (0 degrees) these values work fine,
ObjectX - CarX, ObjectY - CarY, ObjectZ - Carz, Object Z Angle - Car Z Angle.
but not with the rest of angles, so I think that I need a function depending on the offset between the angles and the sin/cos.
Could you please help me on the code to use so I can adapt it to any angle?
Thanks and regards!
Respuesta: Attach object to vehicle (Maths problem, not scripting) -
Siralos - 11.09.2012
Little bump. Thanks!
Respuesta: Attach object to vehicle (Maths problem, not scripting) -
Siralos - 11.09.2012
Just for the record, I found it.
We have to perform two changes of coordinates:
1) Traslation
trx = Object x - Car x
try = Object y - Car y
2) Rotation
final x = trx*cos(CarZ Angle)+try*sin(Car Z Angle)
final y = -trx*sin(CarZ Angle)+try*cos(Car Z Angle)
Then we just have to do:
AttachObjectToVehicle(obj, vehicle, final x, final y, zObj-zVeh, rotxObj, rotyObj, rotzObj - Car Z Angle)
Re: Attach object to vehicle (Maths problem, not scripting) -
Babul - 11.09.2012
had that formula in mind, before i read your solution - iam surprised that you let us know what you've found, its not commonly done here - definetly worth rep. many others should take a slice of your behavior, and let others know what they achieved, after they were "clever" enough to figure out some basic stuff. thank you
Respuesta: Attach object to vehicle (Maths problem, not scripting) -
Siralos - 12.09.2012
Thanks man, I just wrote this because I though not many people knew how to do it... but it seems to be that a lot of people don't want to share their knowledge...
Well, I think this forum is mostly about sharing...