Author Topic: Position Behind a vehicle  (Read 1371 times)

How do I get the position behind a vehicle?
Help appreciated!

Code: [Select]
function getObjectBackPosition(%obj) {
%box = %obj.getWorldBox();
%max = getWords(%box, 3, 6);
%min = getWords(%box, 0, 2);
%size = vectorSub(%max, %min);
%sizeX = getWord(%size, 0);
%sizeY = getWord(%size, 1);
%sizeZ = getWord(%size, 2);
%forward = %obj.getForwardVector();
%scaleX = getWord(%forward, 0) * 0.5;
%scaleY = getWord(%forward, 1) * 0.5;
%scaleZ = getWord(%forward, 2) * 0.5;

return vectorSub(getWords(%obj.getTransform(), 0, 2), %sizeX * %scaleX SPC %sizeY * %scaleY SPC %sizeZ * %scaleZ);
}

I may be overcomplicating it, but it works.
« Last Edit: January 15, 2012, 05:20:06 AM by Destiny/Zack0Wack0 »

getWorldBox isn't 1-to-1 scale, I know from experience.


Plus "behind" would be relative to the vehicle, so you should use getEyeVector instead of getForwardVector.

getWorldBox isn't 1-to-1 scale, I know from experience.


Plus "behind" would be relative to the vehicle, so you should use getEyeVector instead of getForwardVector.
doesn't getForwardVector() return the front of the collision box?

doesn't getForwardVector() return the front of the collision box?

getForwardVector() returns the normalized vector that the object is facing. It has nothing to do with positions.

Well it works perfectly for me, so I'm all good lol.

getWorldBox isn't 1-to-1 scale, I know from experience.
What exactly do you mean "not 1:1 scale"? What other scale is it in? It's only used to get the bounding box of the vehicle.
Plus "behind" would be relative to the vehicle, so you should use getEyeVector instead of getForwardVector.
They are the basically the same thing for vehicles. It already is relative to the vehicle, it uses getForwardVector to rotate the bounding box.
getForwardVector() returns the normalized vector that the object is facing. It has nothing to do with positions.
It doesn't return a position, but it has everything to do with positions.