Sign in to follow this  
Syruz

Game Help (Knockback)

Recommended Posts

Syruz    122
Well here's what needs to be done. If any of you have ever played the old Zelda gameboy games, when you have your shield out the monster bounces back and so do you slightly. Would anyone know how I would approach implementing this same type of thing in my game for each different direction? I'm kinda lost atm, what would be the most efficient way of doing so? (VB if it matters at all.

Share this post


Link to post
Share on other sites
UMichGOBLUE    127
Well if you are looking for just the idea....

You would probably first check for collision detection between your character and a monster. Then if that occurs, check to see if your shield is out. Then move your characters about the screen in a manner that simulates being knocked back.

Share this post


Link to post
Share on other sites
pulpfist    528
You mean that simple 2D Zelda?
Here is C++ pseudo code using very simple trig that could work for a 2D birdsview game


if( collision )
{

// Find angle between player and monster
angle = atan2( monsterCenter.y - playerCenter.y, monsterCenter.x - playerCenter.x );

// knockback monster
monsterCenter.x += cos( angle ) * knockbackVelocity;
monsterCenter.y += sin( angle ) * knockbackVelocity;

// knockback player (opposite direction)
playerCenter.x += cos( angle + PI ) * knockbackVelocity;
playerCenter.y += sin( angle + PI ) * knockbackVelocity;

}


Share this post


Link to post
Share on other sites
Syruz    122
Im guessing atan2 respresents tan squared? Do trig functions work roughly the same in VB?

EDIT: nvm, i figured out what it is.

Share this post


Link to post
Share on other sites
pulpfist    528
Im not too familiar with VB. You might have to write your own arctan2 function
Im not sure my example is what you look for either. Its very simple. I just chipped it in there if nothing else to provoke someone to show a better method =)
There is physics engines available as well, I just thought that would be overkill for a simple game.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this