Bouncing ball using Custom Movement.

Get help using Construct 2

Post » Mon Jul 30, 2012 9:57 pm

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.BlueSkies2012-07-30 22:00:41
B
18
S
4
G
4
Posts: 68
Reputation: 3,127

Post » Wed Aug 01, 2012 4:48 am

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.
B
19
S
5
G
1
Posts: 104
Reputation: 2,920

Post » Fri Aug 10, 2012 6:19 pm

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.
B
18
S
4
G
4
Posts: 68
Reputation: 3,127

Post » Fri Aug 10, 2012 6:58 pm

Here is a way to do it without behaviors:
http://dl.dropbox.com/u/5426011/examples13/45bounce.capx
B
79
S
24
G
53
Posts: 4,728
Reputation: 40,219


Return to How do I....?

Who is online

Users browsing this forum: Eisenhans, michaelverdi and 20 guests