How do I simulate a realistic bouncing ball

Get help using Construct 2

Post » Sun Jan 15, 2017 9:05 am

How do I simulate a realistic bouncing ball without physics... over time it should slow down , bounce less..etc... like a real ball....is it possible ? thanks guys
B
37
S
16
G
2
Posts: 447
Reputation: 4,865

Post » Sun Jan 15, 2017 10:01 am

Without the physics behavior you could use the bullet behavior with gravity. Then when it collides with the ground use the bounce action and set the speed lower.

You could go further by learning the math behind it. Some basic physics course should get you there. There are lots online. Or if you want a specific example there are a few you can find with a forum search.
B
92
S
32
G
107
Posts: 5,280
Reputation: 69,971

Post » Sun Jan 15, 2017 9:08 pm

hi R0J0hound, you seems the king of C2...if you could provide me with a code for realistic bounce +gravity like a ball...it would be amazing.... Math ?... I am totally discalculic and dislexic... would be almost impossible 4 me...

thanks 4 ur time
B
37
S
16
G
2
Posts: 447
Reputation: 4,865

Post » Mon Jan 16, 2017 12:01 am

Sure, here's all that's involved. The velocity increases or accelerates downwards, and the ball it moved by the velocity vertically. Then when the ball hits the ground the velocity is reversed and multiplied by 0.5 to half the next bounce height. You can adjust the gravity by changing the 1 to anything else.

var velocity=0

every tick:
--- add 1 to velocity
--- ball: set y to y+velocity

ball: on collision with ground
--- set velocity to -0.5*velocity
B
92
S
32
G
107
Posts: 5,280
Reputation: 69,971

Post » Mon Jan 16, 2017 7:11 am

thanks a lot... what must I do if it's a ball that I shoot from a cannon that has bullet behavior ?
B
37
S
16
G
2
Posts: 447
Reputation: 4,865

Post » Mon Jan 16, 2017 7:12 am

at the end the ball should stay on ground ...
B
37
S
16
G
2
Posts: 447
Reputation: 4,865

Post » Mon Jan 16, 2017 5:09 pm

If the ground is just flat then the above still holds true. Just change velocity to velocityY and add a velocityX.

When you launch from the cannon you have a speed and angle in mind so you set the velocities with trig:
Set velocityX to speed*cos(ang)
Set velocityY to speed*sin(ang)

And add an event to move horizontally:
Every tick
---ball: set X to x+velocityX

This can get as elaborate as you add more features. I won't be able to explain it all. The physics behavior is there for a reason. It's probably better to use that for what you know.
B
92
S
32
G
107
Posts: 5,280
Reputation: 69,971

Post » Mon Jan 16, 2017 5:19 pm

thanks 4 ur kindness :)
B
37
S
16
G
2
Posts: 447
Reputation: 4,865


Return to How do I....?

Who is online

Users browsing this forum: atmas, NECRONOMICRON and 24 guests