Game Help (Knockback)

Started by
4 comments, last by pulpfist 16 years, 11 months ago
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.
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.
Thats what i need though, how would I go about simulating the knockback in an efficient manner?
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;}
Im guessing atan2 respresents tan squared? Do trig functions work roughly the same in VB?

EDIT: nvm, i figured out what it is.
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.

This topic is closed to new replies.

Advertisement