How do you make an actor bounce back upon contact?

dreph

  • Posts: 142
Greetings!

I am working on a megaman type platformer/shooter, and I am building everything from the ground up.  I am now at a point where I want to make enemies cause damage to player upon contact.  To make things less insane for the player, I want it to bounce them back, and make them invulnerable for 1 second after contact.  The X-speed doesn't seem to happen, although the y does.  The player just bounces up, and not away from the enemy (which is also advancing toward the player, not sure if that has anything to do with my issue).

Here is my code for the bounceback.  I thought 50 was a good speed to set for x, but it doesn't go anywhere.

Also, both the player and the enemy have no friction, but are set as normal actors that can be affected by gravity.  Jumping seems to work just fine, so I think it's something to do with the collision happening too many times in a second, maybe?  The enemy is usually rubbing up against the player with the follow logic I pieced together for enemies.


dreph

  • Posts: 142
Alright well I figured it out, and I figured I would share just in case anyone else had this problem.

This is my first game, and I was basing my left and right movement off of the crash course II.  This included a conditional statement that would set my xspeed to 0 if I wasn't pressing anything.

I deactivated that block of code, fiddled with the friction of my characters back to a logical setting, and tested.  Now my character flies back upon enemy contact damage.

I may add it to the other damage types, but since this is my first game, I think I will just add it only if necessary.  This is a learning project :)

I will upload it as soon as I am done for all of you to enjoy.

taisho

  • Posts: 25
you might want to cancel out the x speed to 0 with a boolean operator. just put it in a if before the x-speed 0

dreph

  • Posts: 142
I ended up getting rid of the X Speed 0, as I mentioned above.  I just set friction to .8, gravity .85, and the kickback actually works now.  Thanks for chiming in :)

I need to get me a license here in the next couple of months so I can make some phone apps :)