SDL Ball Physics WIP

Loading...

Sign in or sign up now!
Alert icon
Upgrade to the latest Flash Player for improved playback performance. Upgrade now or more info.
7,883
Loading...
Alert icon
Sign in or sign up now!
Alert icon

Uploaded by on Sep 18, 2009

Little demonstration of a ball physics engine I've been working on. The aim of creating this was to get more practice at physics programming and to setup the knowledge foundation for making a pinball game if I ever decide to commit to such an idea.

Being a ball physics engine I'm limiting collision response to balls only, other things like the rectangles and arcs are barriers only and do not react when they collide with anything. However I'm aiming at allowing them to move.

One obvious issue with it currently is the slippage of ball through barriers when their velocities are near rest. This is undoubtedly due to gravity so I tried turning gravity off whenever they encounter a surface, it improved the problem but made for unusual behaviour; while rolling on an arc a ball would sometimes experience zero-gravity and roll too high.
I also tried displacing the ball such that it was clear the surface but this caused a snapping effect whenever a ball got near an edge surface enough to trigger the collision response, a side effect much worse than the slippage which it didn't resolve anyway. It did reveal however that the slippage happened because collision response weren't firing off when the velocity magnitude was too small otherwise they never should have slipped past the barrier at all. This suggests the problem is all due to floating point arithmetic error.
Currently a collision occurs when a ball has crossed the line. Perhaps detecting for imminent collisions and responding to them before they happen would improve the slippage issue.
One physics engine I've seen (Phun) has objects actively push outwards at others that manage to dislodge themselves. This seems to be a gentler version of the displacement method I tried and is something I'll definitely try out.

Category:

Science & Technology

Tags:

License:

Standard YouTube License

  • likes, 2 dislikes

Link to this comment:

Share to:

Uploader Comments (oopolka)

  • Looking good. Those are some really bouncy balls though.

    .

    Here's a tip to make it look more realistic:

    When the ball hits an obj, rather than just changing the direction of the velocity, change the speed as well.

    When an object in real life hits another object, some of the energy is transferred, causing the falling object to lose speed.

    .

    in other words:

    When ball A hits a wall, reduce ball A's speed.

    When ball A hits ball B, reduce ball A's speed and increase ball B's speed by the amount lost.

  • @EmbraceTheThunder This is what happens in the simulation.

Top Comments

  • Really nice. You need more collision iterations though to stop the overlapping

see all

All Comments (26)

Sign In or Sign Up now to post a comment!
  • How do you calculate the velocity when 2 objects collide?

  • Really cool! Cool enough to make a tutorial?

  • Really really impressive. Great job! Can we see the SC? I'm just starting out and would love to see how you made this. Thx!

  • Your balls have the fall-through disease...

  • Awesome.

  • i see you like balls :) nah nut awesome physics! I like it

  • Nice, I'm starting at SDL by these days, still don't know how to make collisions with dynamic objects, just pre-defined ones. But it's really interesting how this works, you can use basic Physics to do these things... I guess that if I add mass and momentum to my objects this idea will come to me... :)

  • omg... too amazing...

  • @EmbraceTheThunder actually, increase ball B's speed a little LESS than the amount lost. =P

    not to be picky or anything...

    =P

Loading...
Alert icon
0 / 00Unsaved Playlist Return to active list
    1. Your queue is empty. Add videos to your queue using this button:
      or sign in to load a different list.
    Loading...Loading...Saving...
    • Clear all videos from this list
    • Learn more