Author Topic: Push back with Projectile::OnCollision  (Read 1226 times)

I want the player getting hit to be pushed back.  It doesn't work, and I don't know why.

Code: [Select]
$pushBack::Amount = 15;
package stunstick
{
function stunstickProjectile::OnCollision(%this, %obj, %col, %fade, %pos, %normal)
{
if(%col.getClassName() $= "Player" || %col.getClassName() $= "AIPlayer")
{
%col.setWhiteOut(1);
%col.setVelocity(vectorAdd(%col.getVelocity(),vectorScale(%this.getEyeVector(),$pushBack::Amount)));
}
parent::Oncollision(%this, %obj, %col, %fade, %pos, %normal);
}
};
ActivatePackage(stunstick);

%this.getEyeVector(), you are calling that on a projectile datablock.

%this.getEyeVector(), you are calling that on a projectile datablock.
pretty sure that's the idea, so the player goes in the direction that the projectile was going
instead of the eye vector, could you get the projectile's velocity instead?
or check that the projectile has a valid eye vector

ProjectileData usually doesn't have this function, besides it needs a projectile to get the vector. I think he might have accidentally forgot to change that.

Another thing, it is checking the %col, so it is most likely a mistake.

Instead of %this.getEyeVector() try %obj.getVelocity()

Put a - for the push back amount variable if you want them to go backwards of their direction

Instead of %this.getEyeVector() try %obj.getVelocity()

seems to have no effect
it seems to work sporadically, and blasts people with much greater velocity than the set amount of 15 when it actually works.

ProjectileData usually doesn't have this function, besides it needs a projectile to get the vector. I think he might have accidentally forgot to change that.
I'm pretty sure %col is the object/player being hit.  The whiteout effect in this code applied on %col works after all.
« Last Edit: May 26, 2015, 08:48:41 PM by Tezuni 2.0 »

I was saying that you put %this.getEyeVelocity() which returns nothing because you are calling a non-existing function on a datablock.

Try these.

This only goes from their backward direction.
%col.setVelocity(vectorScale(%col.getForwardVector(), -$pushBack::Amount)); //The - makes it go the opposite way
This uses the way you look and backward direction.
%col.setVelocity(vectorAdd(%col.getEyeVector(), vectorScale(%col.getForwardVector(), -$pushBack::Amount)));
« Last Edit: May 26, 2015, 09:13:59 PM by Advanced Bot »

-redacted because i am a moron-


seems to have no effect
it seems to work sporadically, and blasts people with much greater velocity than the set amount of 15 when it actually works.
try vectornormalize(%obj.getvelocity()) so it'll always have a force of 15 after you scale it

%col.setVelocity(vectorScale(%col.getForwardVector(), -$pushBack::Amount)); //The - makes it go the opposite way
Tried that and it works. Thanks.

I am now trying to stop people abusing it outside the minigame or on teammates, and the code below is broken.
Code: [Select]
                       //checking if anyone involved is outside the minigame, so the effects can be cancelled if true

if(!isObject(%this.minigame) || !isObject(%col.minigame))
return parent::Oncollision(%this, %obj, %col, %fade, %pos, %normal);

%AttackerTeam = %this.getTeam();
%DefenderTeam = %col.getTeam();

//checking if anyone involved is on the same team or allies, so the effects can be cancelled if true

if(%DefenderTeam.name $= "Guards" || %DefenderName.name $= "Warden")
{
if(%AttackerTeam.name $= "Guards" || %AttackerTeam.name $= "Warden")
return parent::Oncollision(%this, %obj, %col, %fade, %pos, %normal);
}

« Last Edit: May 26, 2015, 09:52:17 PM by Tezuni 2.0 »

What you're looking for is %this.client and %col.client since you're calling all those functions on a projectileData and a playerObject.

%this is the projectile datablock, and completely useless.
This is correct, my bad.
« Last Edit: May 28, 2015, 07:26:40 AM by Dannu »

I am now trying to stop people abusing it outside the minigame or on teammates, and the code below is broken.
Code: [Select]
                       //checking if anyone involved is outside the minigame, so the effects can be cancelled if true

if(!isObject(%this.minigame) || !isObject(%col.minigame))
return parent::Oncollision(%this, %obj, %col, %fade, %pos, %normal);


%AttackerTeam = %this.getTeam();
%DefenderTeam = %col.getTeam();

//checking if anyone involved is on the same team or allies, so the effects can be cancelled if true

if(%DefenderTeam.name $= "Guards" || %DefenderName.name $= "Warden")
{
if(%AttackerTeam.name $= "Guards" || %AttackerTeam.name $= "Warden")
return parent::Oncollision(%this, %obj, %col, %fade, %pos, %normal);
}


I think you're still missing what these arguments are.

function stunstickProjectile::OnCollision(%this, %obj, %col, %fade, %pos, %normal)

%this is the projectile datablock, and completely useless.
%obj is the projectile.
%col is the object that got hit.

You'd need to compare %obj.client.getTeam() and %col.client.getTeam()

Also use mingameCanDamage(%attacker, %defender) too, so you can make sure they can damage others.