Bouncing ball using Custom Movement.

0 favourites
  • 5 posts
From the Asset Store
Bouncing ball
$9.99 USD
Template for a bouncing ball game, fully documented in comments and video
  • https://dl.dropbox.com/u/91794570/rebound.capx

    I'm using custom movement rather than the bullet and its in-built bounce functionality because I only want my ball to move at 45 degree angles.

    As you'll see in the capx file, I've managed to get the ball bouncing off the four sides of the box by testing for the ball's position relative to the box and flipping the horizontal or vertical movement accordingly. The problem comes when the ball collides with the corner of the box. In such a case I want both the horizontal and vertical movements to flip, but I can't seem to test for this accurately and without screwing up the rest of the ball's collision detection.

    Help much appreciated.

  • There are lots of ways to go about this: the Custom Movement behavior isn't meant to recreate behaviors like this, as noted on the Custom Movement manual page, and would be best suited for other behaviors, or simply using the Move at Angle command or Bullet behavior with an event to round its angle to 45, 135, 225, or 315. Custom Movement just doesn't give you the capabilities you need.

    Yet if you really want to check for when the ball collides with a corner, (or moves through it, as happened to me when I tested out your .capx,) you should add another event to check for when the ball X/Y is exactly at wall X/Y or inside of it to check for the corner and multiply the custom movement speed by -1 rather than using the reverse function.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Thanks again bWard. I decided to try without custom movement because it was causing one headache. I'm still no further on with bullet movement. Can I ask you what you mean by rounding the angle using bullet behaviour? When do you test for this exactly? On collision? Every tick? I tried both without success.

  • Here is a way to do it without behaviors:

    http://dl.dropbox.com/u/5426011/examples13/45bounce.capx

  • Here is a way to do it without behaviors:

    http://dl.dropbox.com/u/5426011/examples13/45bounce.capx

    Could this bounce ball example be reposted please?

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)