Sign in to follow this  

Game Help (Knockback)

This topic is 3873 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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
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
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
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

This topic is 3873 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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