Jump to content
  • Advertisement
Sign in to follow this  
Syruz

Game Help (Knockback)

This topic is 4090 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
Advertisement
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
Thats what i need though, how would I go about simulating the knockback in an efficient manner?

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 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
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
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!