• entries
    743
  • comments
    1924
  • views
    580404

Edge Walking (and an amusing bug)

Sign in to follow this  

2898 views

Morning.

Was working on improving the shapes for the ragdoll to make them a better fit to the model over the last few days. Made a bit of a mistake with the size of a head sphere, which produced this wonderful out-take I share for your viewing pleassure:



Hope that made you giggle as much as it did me smile.png.

Just hard-coded at the moment, but have added support for a Compound shape to my physics wrapper - basically a wrapper around btCompoundShape, which derives from btCollisionShape and can have as many child shapes added as you wish, each with a local transform, so it fits very seamlessly into the existing system. I'm using these on the lower legs, forearms and head to add some additional shapes that make the ragdoll fit the mesh better, and it seems even more realistic now.

I've also been working on edge walking, by which I mean that when the character is walking rather than running, he stops at the edges a la Tomb Raider.



The first step is a preprocess run on the Physics system after the level has been loaded. I take each polyhedron and generate an initial set of edges which are just the edges of any face that is pointing sufficiently upward (normal's y component is >= 0.8f basically), which are added to a std::map >.

Then I wrote a system that takes in this map as input, runs through and checks each edge against the edges of the other bodies, looking for overlap withing an epsilon. Where overlap is found, it clips the edges so they no longer overlap, either by removing a segment or by breaking a segment into two with a gap in the middle.

Finally I run through all of the final edges and find a point at their middle, moved out from the edge by a small amount, then do a ray cast from this point downwards and check to see if the distance is within a tolerance. If it is, the edge is skipped. For example, before this step there is an edge along the bottom of the diagonal block to the right of the character at startup - because it sits in the middle of another block there is no other edge to clip it against, so this pass gets rid of those.

These final pruned edges are then reassociated with the bodies that generated them, so you can find the edges very easily given a Body.

So we then have a final set of edges which the character controller can test against, basically by doing a radius distance check to the edges associated with the current ground Body and moving the controller back by the right amount when it crosses an edge. Flags to the controller mean this only happens when its move() method is called from Walk state.

Its not quite perfect, had a few issues with some jittering but careful selection of thresholds and tolerances seem to have calmed the beast for now. Will have to see how it pans out with more advanced maps.

These same edges can also be used in the future for edge grabbing and shimmying which I'll probably start to play around with next. I've done this before and the main challenge is getting an animation that looks good, so might wait until I've created a better looking character before I tackle that. Or maybe will just implement it with crappy animations for now. Not sure.

But enough progress to merit a journal update anyway. Thanks, as always, for stopping by.

[EDIT] Since I got featured again (thanks), I thought I'd update a bit. I've managed to sort out the jittering when walking now. Was a problem with a fight happening between the idle and turn states. The turn state wasn't really adding much so I removed it for now until I have a better solution.



Seems to work in all cases, and the nice thing is the edges are generated automatically so there's no user input required to define them.

Next up, I'm going to start looking at edge grabbing and shimmying I think.

[EDIT again] Hmm, actually I fixed the walking by getting rid of the Turn state, but I really miss it so have put it back in. Need to find a better way to fix this. The Turn state means if you try to go from the Idle state to Walk or Run and in a direction that is greater or equal to 90 degrees to the current facing direction, he turns on the spot first, which is really nice and adds a lot of precise control.

The walking jittering seems to be related to fighting between the Walk, Idle and Turn states so need to figure out a way to keep the Turn state without it causing this jittering/fighting. Sure this must be possible.

[EDIT yet again] Ah! Turns out it was a completely different problem that was causing the jittering. The character was switching to the Run state instead of the Walk state.

When I was switching from Idle to movement, I was always switching to Run, then the following frame it was switching to Walk because the Run state checks for the Walk key being held down, but the switch from Idle to move wasn't checking this. Once I fixed this, so that all the states that switch into movement check the Walk key and go directly to Walk instead of Run, all the jittering vanished.

So now it works perfectly well without sacrificing the nice little Turn state.
Sign in to follow this  


0 Comments


Recommended Comments

There are no comments to display.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now