Author Topic: Only check Z velocity?  (Read 488 times)

How would I modify this so it only checks the Z velocity?

Code: [Select]
function PlayerPro::onImpact(%this,%obj,%data)
{
%speed = vectorLen(%obj.getVelocity());
if(%speed > %obj.dataBlock.minImpactSpeed)

%trans = %obj.getTransform();

%p = new Projectile()
{
dataBlock = SmashProjectile;
initialVelocity  = "0 0 0";
initialPosition  = %trans;
sourceObject     = %obj;
sourceSlot       = 0;
client           = %obj.client;
};
MissionCleanup.add(%p);
        if(%obj.destroyed)
            return;
         %obj.schedule(10,"smashExplosion");


}
« Last Edit: December 23, 2009, 09:56:51 AM by Yogurt Man »

Those are incorrect arguements, the correct arguements are %this,%obj,%col,%pos,%speed (I'm fairly sure). Try something like this:
Code: [Select]
function PlayerPro::onImpact(%this,%obj,%col,%pos,%speed)
{
%zVec = getWord(%obj.getVelocity(),2);
if(%zVec <= -(%obj.dataBlock.minImpactSpeed))
{
%p = new Projectile()
{
dataBlock = SmashProjectile;
initialVelocity = "0 0 0";
initialPosition = %obj.getTransform();
sourceObject = %obj;
sourceSlot = 0;
client = %obj.client;
};
MissionCleanup.add(%p);
}
if(!%obj.destroyed)
%obj.schedule(10,"smashExplosion");
}
Note; We check that the Z vector is smaller then the negative of the minImpactSpeed, because Z vector is a negative number when the object is falling.

Thank you!
What about only x and y velocities?

Thank you!
What about only x and y velocities?
%xVec = getWord(%obj.getVelocity(),0);
%yVec = getWord(%obj.getVelocity(),1);