Live data from Hacker News

2D Rigid Body Collision Resolution

sassnow.ski

41–50 of 69 posts

Re: 2D Rigid Body Collision Resolution

#41

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.

I mean there's a lot of material out there already about collision detection though. This feels a bit like seeing a blog post about register allocation and being sad that it doesn't talk about parsing?

Re: 2D Rigid Body Collision Resolution

#43
To learn JS I started with canvas, and without any game dev experience, made a couple of cute little browser games. One is a galaga clone that, for the most part, works OK. The hard part is the projectile collisions. Instead of taking the position of your bullet now, and where it would be in the next time step, and seeing if it would intersect with the enemy hitboxes taken in the same way, I _only_ checked on the current timestep, which means your bullets can magically go around the enemies! Silly stuff. Maybe some day I'll go back and fix it.

Re: 2D Rigid Body Collision Resolution

#44

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…

Feedback: Your introduction "From Mario bouncing off a Goomba..." might be a bit misleading IMO because most games like the classic Super Mario titles on NES and SNES do not require and did not use most of these calculations.

Game development beginners often have the wrong impression that they need rigid body collision calculations or a 2D physics engine like Box2D to handle collisions. That's true if you want to make a game like Pool or something with collapsing stacks of crates like Angry Birds.

But for a 2D platformer you only need to detect collisions by comparing (axis-aligned) rectangles and to handle collisions by changing the moving character's X and Y coordinates (to undo an overlap) or setting the character's Y velocity (after using the jump button, or after landing on a Goomba's head).

This also makes it easier for the developer to finetune exactly how moving the character should feel like. (This includes inertia, but this inertia is usually not physically realistic.) Trying to use realistic physics as a gamedev beginner can easily lead to floaty and unsatisfying movement.

An example tutorial to start with this simple physics-free approach: https://www.love2d.org/wiki/Tutorial:Baseline_2D_Platformer

Re: 2D Rigid Body Collision Resolution

#45

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…

Feedback: You should explain or link to why the two formulations of the dot product are equivalent.

Re: 2D Rigid Body Collision Resolution

#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 player ships are supposed to have difficulty pushing a cluster of heavy objects out of the way, then using a physics library is sensible.

Re: 2D Rigid Body Collision Resolution

#47
post #39
post #21

Earlier quoted context omitted.

It's still the same principle even in games. If you are trying to explain where forces come from and how resolution works, you need to ground it in something. Otherwise you are just adding extra assumptions onto assumptions.

In proper physics simulations, everything's about forces, most things are springs, and you never teleport stuff. In games, modelling the ground as a spring really doesn't work and teleporting entities when they collide with parts of the world often makes a lot of sense. It's just not the same. EDIT: If I'm incorrect, please explain how. I've written some game physics systems and seen some proper physics sim systems a…

The principle of least constraint is the basis for rigid body mechanics based contact forces. This has been known since the days of Gauss and Hamilton, and is fundamentally how restitution and collision forces are derived in Lagrangian mechanics. There's a long literature on this going back more than a hundred years.

It's true that some commercial solvers like Ansys use spring/penalty methods, but this is due to the spring forces being easier to couple to other solvers. It's harder in the Ansys force/velocity formulation to combine things like elasticity and fluids to their rigid body solver. To deal with the instability of systems of many stiff springs they have to take many small timesteps to avoid convergence issues.

More recently techniques like XPBD have been gaining popularity, particularly in film, which use purely positional constraints and variational methods to combine many different types of physics simulations. There's a really great and approachable series of videos by Matthias Muller on youtube which goes through how to implement all this in JS https://matthias-research.github.io/pages/

Finally it's funny you should mention games, since many older games used spring methods for physics. It was only when constraint based solvers became popular after Havok/Half-Life 2 did we start to see games with real rigid body dynamics and stable stacking of boxes. Older physics games like Trespasser ( https://en.wikipedia.org/wiki/Trespasser_(video_game) ) had many bugs due to the use of hacky spring physics. For a good explanation of how games do it today look at Erin Catto's work on Box2D https://box2d.org/publications/

Re: 2D Rigid Body Collision Resolution

#48
post #23
post #17

Collisions are violations of the pairwise non-intersection constraint between bodies. Collision forces are Lagrange multipliers of these constraints. Collision normals are the (normalized) partial derivatives of the constraint function wrt one of the body's configurations.

Neat! do you have a resource that explains this perspective further?

Posted a reply here https://news.ycombinator.com/item?id=40466855

This is a specific reference on how constraints model contact between rigid bodies https://box2d.org/files/ErinCatto_UnderstandingConstraints_G...

Most games since Half Life 2 use constraint forces like this to solve collisions. Springs/penalty forces are still used sometimes in commercial physics solvers since they're easier to couple with other simulations, but they require many small timesteps to ensure convergence.

Re: 2D Rigid Body Collision Resolution

#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/item?id=31261533

Post reply on HN