# Simple bouncy ball example? (No Physics)

Get help using Construct 2

### » Sat Dec 27, 2014 3:28 pm

I made a bouncy ball with the bullet behavior (increase gravity, bounce off solids, etc.) but it's kind of buggy and bounces the wrong way near corners. I'd like to just make one using events but I'm awful at this sort of thing. Anyone mind making or sharing a simple bouncy ball example?
Last edited by Tokinsom on Sat Dec 27, 2014 8:10 pm, edited 1 time in total.
B
248
S
30
G
13
Posts: 1,794
Reputation: 18,909

### » Sat Dec 27, 2014 4:07 pm

Tokinsom no physic only bullets
You do not have the required permissions to view the files attached to this post.
B
262
S
49
G
15
Posts: 2,009
Reputation: 42,233

### » Sat Dec 27, 2014 8:09 pm

As I said, the bullet behavior is too buggy for this. It doesn't handle corners well and occasionally bounces in the wrong direction.
B
248
S
30
G
13
Posts: 1,794
Reputation: 18,909

### » Sat Dec 27, 2014 8:16 pm

You ask for bullet behaviour and not Physics. If you wish to have corner and more then you physic or work out proper coordinate which I don't have time for. Thank you anyway. I tried
B
262
S
49
G
15
Posts: 2,009
Reputation: 42,233

### » Sat Dec 27, 2014 10:17 pm

@Tokinsom
I made this one recently, but corner bouncing can be a bit odd.
viewtopic.php?f=147&t=121046&p=864825&hilit=bounce#p864825

The idea was to try to move horizontally then vertically. So first move the ball horizontally and if it then is overlapping a wall move out of the wall and invert the x velocity. To simplify moving out of the wall I just moved the ball back to it's x position before it moved, which looks good enough. The same is then done in the vertical direction.

Overall it works great for horizontal and vertical walls, but as I said corner bouncing still can look odd. For more accurate corner bouncing we need to find what the ball hit first, a corner or an edge.

Attached is another capx example. To make the bounces even more accurate we just need to improve the normal detecting events. The only complicated looking math is in event 11 when speed_along_normal is set. It's doing a vector dot product which gives us the speed in a certain direction. One thing you can do is check if the ball is touching a corner by seeing if the distance between the ball and a corner is near the radius, then in that case the normal would be the angle from the corner to the ball.

Anyways just some ideas.
You do not have the required permissions to view the files attached to this post.
B
95
S
34
G
128
Posts: 5,493
Reputation: 81,674