Author Topic: Make a bot bounce  (Read 3530 times)

How would I make a bot bounce off a wall like the pong projectile does?

onBotTouch>Bot>SetVelocity>[10 10 10]

onBotTouch>Bot>SetVelocity>[10 10 10]
...

by coding, not events

%bot.setVelocity("10 10 10");

If you want it to bounce off the wall you need to do a lot more math than just setting a static velocity 

If you want it to bounce off the wall you need to do a lot more math than just setting a static velocity 
This is what I thought
so how do you do it? I assume you use vectors and stuff?

This is what I thought


...
by coding, not events
To me, it sounded like you wanted the same way he did it. But in coding. You should specify sooner.

Manage to get your forward vector before you collide (so before you lose your velocity, i believe you just need to do this before you parent the function) then just scale that stuff by -1 and deduct friction (which would probably be defined by you). post your collision function


Code: [Select]
function PuckArmor::onCollision(%this,%obj,%col,%thing,%other)
{

//echo("PUCK COLLUSIONE!!!1!");
if(%col.getType() & $TypeMasks::PlayerObjectType) //Oh and by the way, for some reason it's always calling this even when it's not a player any idea why?
{
%image = %col.getMountedImage(0);
//Echo(%image);
if(isObject(%image) && %image.HockeyStick )
{
echo("reg");
%col.unmountimage( 0 );
//echo("HOCKY STIK W PUCK");
%col.mountImage(HockeyStickWPuckImage, 0);
//echo("has puck");
%col.hasPuck = 1;
%col.hasSportBall = 1;
%obj.delete();
//echo("parent dat sheet");
return;
}
else if(isObject(%image) && %image.GoalieStick )
{
echo("goalie");
%col.unmountimage( 0 );
//echo("HOCKY STIK W PUCK");
%col.mountImage(GoalieStickWPuckImage, 0);
//echo("has puck");
%col.hasPuck = 1;
%col.hasSportBall = 1;
%obj.delete();
return;
}
}

       //Like this??
%objectVelocity = %this.getVelocity();
%fvec = %this.getFowardVector();
%svec = vectorScale(%fvec,-1);
%fvel = vectorScale(%objectVelocity, -1);
%vel = vectorAdd(%fvel,%svec);
%this.setVelocity(%vel);
parent::onCollision(%this,%obj,%col,%thing,%other);
// do onBallHit event, only call this on bricks obviously
if( %col.getType() & $TypeMasks::FxBrickObjectType )
echo("onballhit");
%col.onBallHit( %obj.sourceObject, %obj );

}
This is all of my oncollision function


hockey...
... with the puck being...
an ai...

all i can say is:
nope.
hinthinthint: use a scaled down remodeled ball
« Last Edit: June 16, 2013, 03:49:09 PM by Brian Smithers »

hockey...
... with the puck being...
an ai...

all i can say is:
nope.
hinthinthint: use a scaled down remodeled ball
I tried that at first, but I couldn't get the puck to glide once it landed cuz projectiles suck

Manage to get your forward vector before you collide (so before you lose your velocity, i believe you just need to do this before you parent the function) then just scale that stuff by -1 and deduct friction (which would probably be defined by you). post your collision function

That would just cause it to move back in the exact same path as it came in. How is that bouncing?

Port, can you tell me how to do it the right way?