Wednesday, July 18, 2007

waypoint Arrow for off screen destinations
















I created a "streachy arrow" to point to the next waypoint so the driver can find his way around a foreign place to his destination. Took some fenagling, and the usual trig + vector math, but nothing to harry. I used some functions from my other game in development "Red Shift" to help this along. It's nice to borrow from your other projects.. makes things go faster sometimes.



example of the angle function:

function calculateAngle(%source,%target)
{
// get the desired angle required to point at the target
%vec = t2dVectorSub(%source, %target);

%angle = -mRadToDeg(mATan(getWord(%vec,0),getWord(%vec,1))); return %angle;
}

setting the position, and vector length etc, for the destination vector.

function updateDestinationArrow(){
%tmp = $pCar.getPosition();

%tmp1 = $waypoint[$currentTarget.parkOrder+1].getPosition();
%angleVector=calculateAngle(%tmp,%tmp1);
%angleAdd=t2dVectorDistance(%tmp1,%tmp);
%angleAdd*=2; //double the lengh since I'm using a half image

$destinationArrow.setRotation(%angleVector-90);
$destinationArrow.setWidth(%angleAdd);
$destinationArrow.setPosition($pCar.getPosition());
}

No comments: