Live data from Hacker News

2D Rigid Body Collision Resolution

sassnow.ski

51–60 of 69 posts

Re: 2D Rigid Body Collision Resolution

#51

I know this post is focused on collision resolution, but I was still a little disappointed to see collision detection handwaved away. In my experience that's where the real headscratchers are.

Completely disagree - convex collision detection is a neatly solved problem. SAT [0] is implementable in a couple of hours, and GJK [1] is a really neat algorithm that takes a ltitle more than SAT to implement. For optimising collision detection there's some spatial partitioning [2] algorithms that work really well.

The gnarly stuff comes in when you're trying to figure out contact points and impulse responses and apply them without blowing everything up. I've written some of this stuff for a few games now, and the resources below have stood the test of time IMO

[0] https://dyn4j.org/2010/01/sat/ [1] https://realtimecollisiondetection.net/pubs/SIGGRAPH04_Erics... [2] https://allenchou.net/2013/12/game-physics-broadphase/

Re: 2D Rigid Body Collision Resolution

#53
post #46

One side project I am working on right now is a 2d space shooter I am developing with my son. The idea is to have top down look, have each player control some kind of ship and fly in an enclosed area filled with space debris and shot opponents. An important aspect of this game is that the space debris can be moved around the arena and used creatively to capture opponents, prevent them from achieving their goals, etc.…

Did your game require realistic physics collisions? If not, this might be unnecessary complexity. Almost no 2D shoot'em up game before 2000, and very few afterwards, go this route. Here's the common method to make a shmup with very simple rectangle comparisons: https://kidscancode.org/blog/2016/08/pygame_shmup_part_3/ But if your space debris objects are supposed to collide and agglomerate realistically, and if the p…

It does requires realistic collisions.

The point is you fly in a small spaceship in an arena, you hide behind obstacles, you shoot with a small variety of weapons and you use your weapons to either shoot the enemy directly or rearrange the map to make life difficult for your them. The collisions need to be realistic because you need to be able to predict what is going to happen when you hit things a certain way.

It is just a concept we are playing with.

Another part of that concept is that this game is meant for small kids that can't read. There is not a single letter or digit in the entire game. No menu. You just start the controller and get immediately pulled into the game.

And another feature is we wanted the game fun because the control feel fun and immediate. So we are experimenting a lot with what it means for the controls to be enjoyable.

Re: 2D Rigid Body Collision Resolution

#54

Hey everyone, author here! To give some context, this is only part one in a series of blog posts I plan on writing about rigid body physics. The post is aimed at people like myself, who aren't game devs and don't necessarily have a strong math background. Which is why I spend so much time explaining concepts that would appear almost trivial to someone who has experience in this area. Happy to answer any questions you…

Sounds intriguing! I’m probably your ideal audience, given a large coding background, low math background, and current writing 2D focused games.

If I may ask a question, in your mind what’s the benefit of more deeply understanding these implementations when physics frameworks handle a lot of the really mathy logic behind collisions and simulations.

Either way I’m putting this in my read queue. Thanks!

Re: 2D Rigid Body Collision Resolution

#55
post #46

One side project I am working on right now is a 2d space shooter I am developing with my son. The idea is to have top down look, have each player control some kind of ship and fly in an enclosed area filled with space debris and shot opponents. An important aspect of this game is that the space debris can be moved around the arena and used creatively to capture opponents, prevent them from achieving their goals, etc.…

Did your game require realistic physics collisions? If not, this might be unnecessary complexity. Almost no 2D shoot'em up game before 2000, and very few afterwards, go this route. Here's the common method to make a shmup with very simple rectangle comparisons: https://kidscancode.org/blog/2016/08/pygame_shmup_part_3/ But if your space debris objects are supposed to collide and agglomerate realistically, and if the p…

I think it is waaaaay easier and likely more performant to just use a subset of Box2D or (rapier), than implementing simple physic yourself.

They are quite optimized and performant libaries already and there are tons of tutorials for box2d out there (thanks to iforce).

You just add some shapes of your liking and call world.step

Re: 2D Rigid Body Collision Resolution

#56
post #51

I know this post is focused on collision resolution, but I was still a little disappointed to see collision detection handwaved away. In my experience that's where the real headscratchers are.

Completely disagree - convex collision detection is a neatly solved problem. SAT [0] is implementable in a couple of hours, and GJK [1] is a really neat algorithm that takes a ltitle more than SAT to implement. For optimising collision detection there's some spatial partitioning [2] algorithms that work really well. The gnarly stuff comes in when you're trying to figure out contact points and impulse responses and ap…

Well yeah, people often assume that because they know how to tell if two shapes are currently intersecting, they've solved collision detection...and then their games turn out to have a bunch of detection-related bugs and glitches. Most notoriously, lots of homebrewed physics libraries suffer badly from tunnelling (i.e. when one or both bodies are moving so fast that they completely pass through another before the next time collision is naively checked, and so the checker fails to detect a collision at all).

And on top of that there is more to collision detection than just code IMO - setting up hitboxes that both feel right for the player and aren't visually glitchy is not as straightforward as it might seem, especially with 3D.

(Also, figuring out contact points is part of competently implemented collision detection.)

Re: 2D Rigid Body Collision Resolution

#58
post #50

Oh! Look, a well-researched, deeply-explained, and interactive post. Honestly, when I initially read the domain name and noticed the TLD is " .ski " I was thinking it is from the author who wrote about Mecanical Watch [1] and other cool stuff.. it turned out to be a totally different one but of similar quality. What's the secret sauce behind this " .ski " TLD :) ___________________ 1. https://news.ycombinator.com/ite…

There is very simple reason for this: "ski" it the most common suffix of Polish surnames, of which the most popular is Kowalski. There are a lot of people out there either Polish or with Polish origins.

Author of https://ciechanow.ski – the site we all love here – is Polish programmer working for Apple.

Re: 2D Rigid Body Collision Resolution

#59

Hey everyone, author here! To give some context, this is only part one in a series of blog posts I plan on writing about rigid body physics. The post is aimed at people like myself, who aren't game devs and don't necessarily have a strong math background. Which is why I spend so much time explaining concepts that would appear almost trivial to someone who has experience in this area. Happy to answer any questions you…

I love anything having to do with matrices. This is great!
Post reply on HN