Sunday, 25 August 2013

Mobs living in the physics engine

Mobs living in the physics engine

So, yeah. Mobs (including, and indeed especially, the player), physics
engine running (cannon.js), first-person perspective, fairly
low-poly-count world because I'm targeting WebGL. I'm trying to represent
my mobs within the physics engine, moving them by applying forces or
impulses, and I'm having some problems:
1) Ramps! The FPS Way seems to be that critters run uphill and downhill
and on the flat, all at the same speed. But of course
even-slightly-realistic physics really wants you to go slower uphill,
especially if you add friction to prevent "standing" mobs from sliding
downhill. I've tried compensating for this by calculating how fast the mob
"wants" to go, and applying force proportionate to the difference between
its actual velocity and desired velocity, but it just Ain't Right. Also,
the mobs have a tendency to jump up off the top of staircases.
2) Falling over! To make the mobs collide with things, they have to be
represented by some appropriate shape. I've tried a few different ones.
Particles are an obvious lose, and fall into every possible crack in the
geometry. A box the approximate shape of the bounding box for a standing
person falls over constantly, especially on slopes. Putting the center of
mass for the object at the bottom of the box helps, but only somewhat.
Using a lower, flatter shape-- think "coin with beveled edges"-- prevents
the falling down, but fails at detecting collisions. The last thing I
tried was a sort of egg shape, which stays up but staggers like a drunken
sailor.
Obviously, I'm missing something. What? Do people just have to have
Special Physics Of Their Own? Should I toss the whole thing and write that
car game instead?

No comments:

Post a Comment