Game Development Community

impulse on XY only issue (done)

by Steve Acaster · in Torque 3D Professional · 08/14/2010 (11:10 am) · 2 replies

In 1.1b1, I'd scripted a projectile impulse which pretty much ignored the Z axis (simply by dropping it from the applied impulse), thus knocking a player sideways without throwing them in the air if they got shot in the front.

Since 1.1b2 my hacky bit of script no longer functions as desired, and players jump/impulse into the air if shot in the foot ... which looks silly ...

Anyone any ideas on how I can apply an XY impulse without Z?

function bulletimpulse(%col, %pos, %directdamage)
{
		%directimpulse = %directdamage * 60;
		
		%impulseVec = VectorSub(%col.getWorldBoxCenter(), %pos);
		// %impulseVec = VectorSub(%col.getPosition(), %pos);// don't use this - it all goes to buggeration and adds headshot for unknown reason

        %impulseVec = VectorNormalize(%impulseVec);

		%impulseVec = VectorScale(%impulseVec, %directimpulse);

		%impulseVec = getwords(%impulseVec,0,1);//just ignore z

		%col.applyImpulse(%pos, %impulseVec);
}

#1
08/14/2010 (11:50 am)
Dropping the Z axis from the impact position prior to normalizing seems to do the trick. That way it just leaves the collision object's worldboxcenter Z axis intact for the impulse to affect.

%pos = getwords(%pos,0,1);
		%impulseVec = VectorSub(%col.getWorldBoxCenter(), %pos);
#2
08/14/2010 (9:03 pm)
Impulse is a force vector, so really you just want to make sure that you always manually set the Z component to 0 instead of actually leaving it blank if you don't want any up/down force.

I think your original code should work if you change the second to last line to
%impulseVec = getwords(%impulseVec,0,1) @ " 0";

Why it used to work with just a blank before I can't say... not sure what happens in the engine if it gets a value from the script like "X Y" when it's expecting "X Y Z" to fill a Point3F. I'm guessing somewhere in the recent changes to the script engine sending just "X Y" results in Z being an uninitialized value at code-level where it used to fill in a 0 internally.