Bounce around with raycasting

Decided to see if I could make something bounce off surfaces.

Only used my intuition, instead of doing the right thing and researching a little :slight_smile: I’m assuming this is not the best way to do this type of physics simulation.

Here’s the elevator pitch:

  • See if the ball will enter the mesh, given its current velocity
  • If inside the mesh (collision), cast a ray equal to its negative velocity
  • grab the face normal hit by the ray, update the balls velocity

This is me reinventing this wheel, would love to hear any other ways to do this

https://chrisboligprojects.pythonanywhere.com/bounceAround
https://chrisboligprojects.pythonanywhere.com/targetBounce

bounce around:


try to hit the target

6 Likes

Looks good!

The main extra stuff that physics engines do is putting things in a search structure like a bvh tree to make those raycasts faster… and they use separating axis theorem to detect collisions… but you’ve captured the case of box->sphere collision pretty well it looks like.

2 Likes

hmm, interesting. Thanks for mentioning those methods so I can look into them later! I really liked this one, so I think I might have a few more projects similar to this in the future.