Author Topic: Finding a point...  (Read 615 times)

How would I find a point in space 10 units in front of something? Like the position of an object, except 10 units added in the direction it is facing?

Get the forward vector, multiply it by 10 then add it to the object's position.

So is this right?
Code: [Select]
%position=VectorAdd(%this.getTransform,%this.getForwardVector()*10);

You cant multiply a vector by an integer, you have to use vectorScale(vector,scale)

Furthermore I'm not even sure what getForwardVector does, I remember it being curiously misleading though. I'd pick whatever axis you decide the front of the object is, then scale that normalized vector. So if you decide the front is positive Y, scale "0 1 0" by 10.

It's not a static object though...

An object always has a relative XYZ axis. The front of the player is always Y+ for example, I think.

You cant multiply a vector by an integer, you have to use vectorScale(vector,scale)

Furthermore I'm not even sure what getForwardVector does, I remember it being curiously misleading though. I'd pick whatever axis you decide the front of the object is, then scale that normalized vector. So if you decide the front is positive Y, scale "0 1 0" by 10.
For Player objects, anyway, getForwardVector returns the horizontal component of the direction they are facing. getEyeVector returns the way they are aiming, but this also includes Free Look - aiming behind you and firing weapons like the Shotgun will cause the recoil to go forwards. I usually combine them to get the correct aiming vector:
Code: [Select]
%fvec = %obj.getForwardVector();
%fX = getWord(%fvec,0);
%fY = getWord(%fvec,1);

%evec = %obj.getEyeVector();
%eX = getWord(%evec,0);
%eY = getWord(%evec,1);
%eZ = getWord(%evec,2);

%eXY = mSqrt(%eX*%eX+%eY*%eY);

%aimVec = %fX*%eXY SPC %fY*%eXY SPC %eZ;
You'd then scale %aimVec by ten and add it to the object's eye point.

This probably applies to vehicles etc. if you're controlling them, too, but I haven't tested.
« Last Edit: May 10, 2009, 01:55:29 AM by Space Guy »