Public Group

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

## 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 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 on other sites
Thats what i need though, how would I go about simulating the knockback in an efficient manner?

##### 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 monsterangle = atan2( monsterCenter.y - playerCenter.y, monsterCenter.x - playerCenter.x );// knockback monstermonsterCenter.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 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 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.

1. 1
2. 2
3. 3
Rutin
19
4. 4
5. 5

• 14
• 30
• 13
• 11
• 11
• ### Forum Statistics

• Total Topics
631780
• Total Posts
3002314
×