views:

157

answers:

2

I'm moving a character (ellipsoid) around in my physics engine. The movement must be constrained by the static geometry, but should slide on the edges, so it won't be stuck.

My current approach is to move it a little and then push it back out of the geometry. It seems to work, but I think it's mostly because of luck. I fear there must be some corner cases where this method will go haywire. For example a sharp corner where two walls keeps pushing the character into each other.

How would a "state of the art" game engine solve this?

+1  A: 

I have not developed a state of the art game engine, but I once wrote a racing game where collision was simply handled by reversing the simulation time and calculate where the edge was crossed. Then the car was allowed to bounce back into the game field. The penalty was that the controls was disabled until the car stopped.

So my suggestion is that you run your physics engine to calculate exactly where the edge is hit (it might need some non-linear equation solving approach), then you change your velocity vector to either bounce off or follow the edge.

In the case of protecting against corner cases, one could always keep a history of the last valid position within the game and state of the physics engine. If the game gets stuck, the simulation can be restarted from that point but with a different condition (say by adding some randomization to the internal parameters).

Ernelli
Hi Ernelli, thanks for the suggestion. It seems like a good idea to stop time at the exact time of collision. I fear the math is too tricky for a general solution, where the objects can be rotating. However for this specific case (ellipsoid vs. static geometry) I think I could manage the math.
LaZe
+1  A: 

Consider using a 3rd party physics library such as Chipmunk-physics or Box2D. When it comes to game physics, anything beyond the most basic stuff can be quite complex, and there's no need to reinvent the wheel.

Usually the problem you mention is solved by determining the amount of overlap, contact points and surface normals (e.g., by using separating-axis theorem). Then impulses are calculated and applied, which change object velocities, so that in the next iteration the objects are moved apart in a physically realistic way.

atis
Hi atis, I have already got the physics working with separating-axis collision detection for convex meshes and impulse-based collision response with friction. I really want to do all this nitty gritty stuff myself. It's a hobby project, so my priority is to learn and code some fun stuff. :-)
LaZe
Cool, Oh and you're doing it in 3d. Btw it's not uncommon to see "artifacts" in other physics engines when two collisions are solved simultaneously and move the object in nearly opposite directions which can make the object bounce around a little. Damping and friction lessen these effects, but it is indeed something that exists and I guess is hard to deal with nicely.
atis