Movement: hitting target and bouncing in OPPOSITE direction? SOLVED!

infinitum3d

  • Posts: 89
I'm using the ATAN2 function to set an actor in motion from the center of the left side of the scene (x=0, y=240) toward a target actor by mouse click.  So far, so good.  When the actor gets to the target, I want it to reverse direction and return to (0,240) but "bounce" behavior ricochets off like a billiard ball at an angle.

I tried saying 'on collision' direction=direction + 180 degrees but didn't work.  I tried direction=negate (direction) but didn't work.

Any suggestions?  Do I have to recalculate ATAN2 using the collision coordinates or is there a simple solution?

Thanks!

« Last Edit: May 06, 2014, 07:00:08 pm by infinitum3d »

Tuo

  • *
  • Posts: 2469
The simplest way is to "set x-speed to [negate [x-speed]]"

If you prefer to do the trig though, remember that a left/right bounce means that you can take 360 - angle to get the bounce (and vertical is 180 - angle).
Don't look to me but rather to the One who is the reason for what I do. :)

If you need help, send me a PM. Even if I haven't been on in the forums in ages, I still receive those messages via email notifications. You can also reply to any of my forum posts, regardless of the age (especially if I created it), and I will likely reply.

If you want to see the programming behind certain types of games, feel free to check out my "Demo-" games on StencylForge (http://community.stencyl.com/index.php/topic,16160.0.html)

infinitum3d

  • Posts: 89
Hmmm... That didn't work for me.

I was able to use the trig function atan2(y2-y1 x2-x1) by reversing my factors to compensate for the new starting/ending coordinates.