Mooving Parts

Published November 22, 2007
Advertisement
With a shiny new Maya plugin under my belt, I was ready to tackle the real problem: mooving parts. A few weeks ago, a friend challenged me with a ferris wheel model (a spinning wheel with platforms you can ride around on). After sorting out a few animation pivot issues, I brought the wheel-o-doom into my engine, only to watch the little cow slide off and even pass clean through the platforms as they careered about. After a bit of head scratching, I realised the problem: the whole collection of moving parts (the wheel and all the attached platforms) were being assembled into an animated skeleton ... but there was only one physics body for the whole assembly. So while the platforms were dutifully whirling about on their bones, the skeleton itself wasn't actually moving - so the physics body representing it cheerfully told the physics engine there was no motion. No motion means no friction - hence the cow sliding off as the platform animates past. No motion also means no fast-body ray-cast collision test, which leads to tunnelling in the collision detection - hence the collision failures.

The fix was to give each solid mooving part a unique physics body inside the skeleton (something I'd wanted to add as preparation for rag doll anyway). Whenever a physics body is present, the skeletal animation system passes any animation motion to the physics body, rather than directly repositioning the attached objects (i.e. the platforms). The maths to calculate a smooth rotation motion vector for an arbitrary point in the skeleton was not pleasant. It was at this point though that I hit a total road block on my old Maya plugin - there was no fine grain control over where game objects were attached, or which properties (solid, ethereal, immovable, etc) applied to which shapes in a skeleton. With the new plugin I covered last time, I can not only describe exactly where they go, but it's so easy to use, I can enjoy it.

Anyway here's a quick video of the result - I can now create large animated machines for Milkshake to play with, and like everything else, they can be hooked up to other game elements like switches: (click for the movie - the switch output is hooked to a multiply node (x2) then to an addition node (-1) and then into the animation controller speed inputs to get it to reverse all the animations)

Disabled

The biggest outstanding issue is high-friction physics - something I totally underestimated. You see, most of the physics solver approaches I've played with (successive impulse, LCP) fall down horribly in high friction scenarios. As soon as you crank up the friction force to a point that Milkshake doesn't slide around on a moving platform, he also magically gains the power to force himself through walls (as the friction force overpowers the penetration correction force - and if you raise the penetration correction force to compensate, not only does the friction get even stronger (as friction is proportional to normal force incident on the point of contact), but objects just start bouncing off everything due to the enormous response forces). I quickly found myself in a horribly interconnected web of force balancing - I'd change a parameter or calculation to fix one scenario, only to totally break another one that I didn't notice for a day or so.

To give myself a little more confidence trying out new physics solutions, I've written a physics test script which runs through a few minutes of tests (pushing lots of different configurations of blocks, riding moving platforms, walking into different sized gaps, etc) so I could quickly see how a given change effects all the aspects of the gameplay I was interested in.

The video above is taken using my current physics prototype (similar to the Tomb Raider Legend solver, but using a decaying friction term) - I still need to add anisotropic friction for the main character and solve friction handling in stacks of blocks - but other than that, it looks promising. Still, if anyone has any insights into handling high-friction physics - drop me a line.


Cheers!
Previous Entry Maya Integration
Next Entry Particle Fan
0 likes 11 comments

Comments

Jotaf
Awesomeness!!

But I can't really help you at this time in the night (or morning...) so I'll stop writing here (for now).
November 22, 2007 10:22 PM
mightypigeon
Moo!

Wish I could help you out. But I'm not too good with that physics stuff :)

I'd just like to say I've been watching your journal for a while now. This game looks like it's going to be awesome! Love your art style :)
November 23, 2007 07:31 PM
Jotaf
A small suggestion for the high friction thing. There's actually a *limit* for friction, and you're not considering it. There's a sort of break-down point when you start having slippage, and after that the friction force stops growing and always stays the same. Actually, immediately after the slippage point, it will decrease a little. Like so: (beware ascii graphics!)

^ Friction
|
| . ./|_________
| ./
|/____________> Force


If you do that, Milkshake will start pushing the wall, but after a certain limit his feet will start slipping on the floor and he can't apply any more force to the wall :)
November 23, 2007 10:07 PM
Aiursrage
Looking really good!
What are you using for phyiscs?
November 24, 2007 12:43 AM
Milkshake
Quote:Original post by mightypigeon
I'd just like to say I've been watching your journal for a while now. This game looks like it's going to be awesome! Love your art style :)


Thanks MP - it's surprisingly satisfyling to hear from people who like your creation. It can be a really long slog to actually get something out there on your own (and after following radioactive software's journal - I think I've even underestimated it) - so a little encouragement along the way really helps you keep moving.

Quote:Original post by Aiursrage
Looking really good!
What are you using for phyiscs?


And thank you too =) I'll answer this one first as it'll put Jotaf's comment in context a little better. I wanted to have a "realistic" physics simulation, but I wanted to be able to bend the rules where gameplay needed it - and there's only so far you can bend an existing library - so I wrote a few of my own. Time will tell whether this actually turns out to be a good thing - but if nothing else, it's helped me understand a lot more of what my physics (and collision) options are, how they work, and how I can use them.

I know I'd be experimenting with different physics solutions to get the "feel" i wanted, so I wrote my engine so I could plug in different physics modules really easily (there's a line in the initialisation script which says "new MI6Physics" or whichever solver I want to use right now.

Right now, there are 5 different physics solvers in my code base, all in various stages of usefulness. There's an "accurate" LCP based solver that just tries to be as "real" as it can. There's a more forgiving LCP solver which adds a few concessions to the end gameplay I'm hoping to use - so for example, it allows you to bias how correction forces are balanced between the two bodes in a constraint so you can do entirely inaccurate (but good for the gameplay I want) things like only having friction drive the top-most body. There's similarly an accurate and a gameplay-focused succussive impulse solver. I know in theory, SI and LCP are mathenmatically equivalent - but at least in my implementation they have their own character. The LCP is more even handed, and the SI solver is much easier to understand and add custom behaviour too. And then I've also started an "Isometric" physics solver which just tries to reproduce the feel of the old isometric games (they have no rotation - which feels really weird after playing with the other models).

Which brings me nicely to Jotaf's suggestion:

Quote:Original post by Jotaf
A small suggestion for the high friction thing. There's actually a *limit* for friction, and you're not considering it. There's a sort of break-down point when you start having slippage, and after that the friction force stops growing and always stays the same. Actually, immediately after the slippage point, it will decrease a little. Like so: (beware ascii graphics!)

^ Friction
|
| . ./|_________
| ./
|/____________> Force


If you do that, Milkshake will start pushing the wall, but after a certain limit his feet will start slipping on the floor and he can't apply any more force to the wall :)


Thanks for both the encouragement and the suggestion! No man is an indie coding island ... or at least, not this man, so it's great to get some other ideas.

Adding a friction limit is certainly intriguing. Pardon my rambling, but I'm going to walk myself through this problem out loud - perhaps you can find the hole in my reasoning (and code).

So right now, (like ODE) I have two friction models (well, I think ODE has at least the remenants of several others too): there's a normal force DEpenedent friction limit version, and a normal force INdepedent friction limit version. In the real world, the friction force is roughly proportional to the normal force passing through the contact point - the harder you push two surfaces together, the harder it is the slide them along - and this model also has some very nice gameplay implications too: it means pushing a stack of 2 blocks is twice as hard/slow as pushing a single block; and it means that pushing a block over a single big plane sees the same resistance/push-speed as pushing it over the intersection of 4 tiles. So the following assumes we're using normal force dependent friction.

Now, the next strand of the problem comes from trying to walk around on a moving platform. When you're walking on a mooving platform, and either you or the platform makes an instantaneous change of direction, the engine needs to be able to apply an impulse large enough to enact the change across a single physics timestep, or else the character slips around (something I don't want - if I allow some character slip, the solution is totally stable, but it's sloppy). The problem comes from the fact that the acceleration of said impulse far exceeds the acceleration of gravity (as in most fantasy universes like Mario, you actually have an amazingly low gravity relative to the real world to stop things plunging at frightening speeds towards the ground. So, the friction constant used to calculate the friction limit from the normal force is noticeably larger than 1.

Which brings us to the final piece of the problem: restitution force. Both of my solutions are so-called "discrete collision" systems. This means that they let intersections happen, then they try and fix it (and interestingly, for stable systems, they usually try and leave a small bit of inter-penetration around, usually referred to as the surface thickness or something). So, when you're character is standing on (or falling into) the ground, the solver doesn't actually "fix" the whole penetration every time step - because if it did, your character would actually bounce off the ground. Instead, it fixes some constantly-defined proportion of the penetration, usually around 50%. If you make this constant too low, things just smoosh through each other. Make it too high and things bounce off.

So, looking at the combined effect of applying all these rules to the situation where your character is walking full-pelt into a wall, you get the horrible net-effect that, to avoid bounciness, the solver only tries to apply around half of the force necessary to correct the character's incursion into the wall. But to give you a totally sticky "run around on a moving platform" behaviour, it's also been told it can use a force at least as big as the acceleration of the character in the first place (as anything smaller means slip on a moving platform). So the friction force is 100% of the incursion force (or more) - meaning it slowly but surely forces you through the wall.

Does all that make sense?

So even if I added a friction cutoff for the force-dependent friction, won't setting it low enough to stop you overpowering the wall mean it's insufficient to apply an impulse large enough to have the character stick to a moving platform changing direction?

The closest I've come so far is the play around with some low slip values - trading off a tiny amount of slop in th
November 24, 2007 03:22 AM
Jotaf
The problem is that if you let the friction force grow uncontrolled, it will in some situations overpower everything else. You should have a cutoff, even if it's set really high, because it's sensible that if something is applying too much force, friction shouldn't back it up, there should be some slippage.

Your point is valid, and it happens in real life; if you're standing on something that's moving and it changes direction abruptly (with an impulse force greater than the cutoff), you will probably slip and fall down! Unless your soles can grab the floor really well. But consider the alternative, if the cutoff is set too high, and you try to push a wall, *all* of the force you're applying will be transfered to the wall. Overpowering the reaction force of a wall in real life usually means tearing it apart. The cutoff acts as negative feedback on the system and counters this. You would still have to tune some values to make it stable (like with all other negative-feedback control systems) but it isn't so bad :)

BTW, what should the engine do when you're pushing a heavy stack of crates? It should slow you down to reflect the weight. What about the limit situation, when the stack of crates you're pushing is too heavy to be pushed? Ideally, the poor cow's feet should slip. Otherwise something would have to break to release all that energy! This is the same as with a wall, something that should not be pushed.
November 24, 2007 03:57 PM
Todo
Absolutely astounding progress and cute to boot :-).
November 26, 2007 06:50 AM
Milkshake
Quote:Original post by Jotaf
The problem is that if you let the friction force grow uncontrolled, it will in some situations overpower everything else. You should have a cutoff, even if it's set really high, because it's sensible that if something is applying too much force, friction shouldn't back it up, there should be some slippage.

Your point is valid, and it happens in real life; if you're standing on something that's moving and it changes direction abruptly (with an impulse force greater than the cutoff), you will probably slip and fall down! Unless your soles can grab the floor really well. But consider the alternative, if the cutoff is set too high, and you try to push a wall, *all* of the force you're applying will be transfered to the wall. Overpowering the reaction force of a wall in real life usually means tearing it apart. The cutoff acts as negative feedback on the system and counters this. You would still have to tune some values to make it stable (like with all other negative-feedback control systems) but it isn't so bad :)

BTW, what should the engine do when you're pushing a heavy stack of crates? It should slow you down to reflect the weight. What about the limit situation, when the stack of crates you're pushing is too heavy to be pushed? Ideally, the poor cow's feet should slip. Otherwise something would have to break to release all that energy! This is the same as with a wall, something that should not be pushed.


Great to have someone to bounce this stuff off Jotaf - thanks!

So I totally agree with you - I do see the value of a friction limit. But I think there might still be a scenario where this breaks down. Imagine the 'X's in the horrible ascii art below represent your character, and you're trying to make him walk under a ceiling that is angling down toward the ground (creating a recess that is not high enough for the character). [EDIT - the diagram below is totally hosed by the proportional font - I guess you'll have to use your imagination]

*--.__
X *--.__
X ->
X
------------

Let's say the friction force limit is Mu. And, in order to get nice high friction response, Mu is significantly greater than gravity. So, at the ground contact point, your walking character will exert the full force Mu along his direction of motion (right) because the ground normal is totally perpendicular. But at the ceiling, the normal is not quite perpedicular because of the angle of the roof - so Mu gets applied up and to the left (to try and stop the motion). Now if we ignore the normal force from the roof given that Mu is significantly larger than gravity, won't the friction force from the ground still "win", driving the character into the gap that he really shouldn't fit into? This is what happens when I run the simulation at any rate.
November 26, 2007 10:33 AM
Jotaf
Quote:Original post by Milkshake
Great to have someone to bounce this stuff off Jotaf - thanks!

So I totally agree with you - I do see the value of a friction limit. But I think there might still be a scenario where this breaks down. Imagine the 'X's in the horrible ascii art below represent your character, and you're trying to make him walk under a ceiling that is angling down toward the ground (creating a recess that is not high enough for the character). [EDIT - the diagram below is totally hosed by the proportional font - I guess you'll have to use your imagination]

*--.__
X *--.__
X ->
X
------------

Let's say the friction force limit is Mu. And, in order to get nice high friction response, Mu is significantly greater than gravity. So, at the ground contact point, your walking character will exert the full force Mu along his direction of motion (right) because the ground normal is totally perpendicular. But at the ceiling, the normal is not quite perpedicular because of the angle of the roof - so Mu gets applied up and to the left (to try and stop the motion). Now if we ignore the normal force from the roof given that Mu is significantly larger than gravity, won't the friction force from the ground still "win", driving the character into the gap that he really shouldn't fit into? This is what happens when I run the simulation at any rate.


Well, I can see where you're going, but from a gameplay perspective this is a bit contrived and shouldn't be seen as a total failure. That's the engineer in me talking :) As a last resort you can just not have that kind of geometry in the game.

Of course the perfectionist in me is intrigued by the challenge :P To be honest I don't quite understand your explanation. This is how I would probably analyze the situation: Milkshake exerts a (unnatural) force on the ground and gets a friction as a response, driving it onwards. There's an intersection with the ground so there will be a normal force to counter the sum of all other forces (friction + gravity, projected on the normal => countering just gravity).

As soon as the roof is hit, there's another normal force in play. The problem is that if they're defined in this way they become mutually dependent; computing one changes the sum of all forces which influences the other one, which in turn... you get the idea. How would you handle that? Simple accumulators don't seem to work. Is there an obvious answer I missed? Perhaps in your earlier explanation which my tired brain could not defuse :)

Given that interactions between different normal forces acting on the same rigid body can become quite complicated, I thought of a different solution: what about if your character (and maybe objects in general) is defined by a set of springs? Arranged as the edges of a cube or similar. Any object caught between 2 or more normals would "squish", absorbing the energy in question (a rigid body would be subject to a lot of stress if it's forced in an inverted wedge like this).

I just noticed that I didn't even mention the friction limit at all. I don't think it would fill a big role in the situation that you describe... except as the initial force, but then, inertia could do the same (throw the object in the air into the same geometry).

Glad to discuss some old-school physics too, from my 1nd year onward the most physics I had was about wave and electromagnetic fields :)
November 26, 2007 09:31 PM
RAZORUNREAL
Do the platforms really need to change direction suddenly? If they moved more smoothly it wouldn't be an issue.
November 27, 2007 12:10 AM
Milkshake
Quote:Original post by RAZORUNREAL
Do the platforms really need to change direction suddenly? If they moved more smoothly it wouldn't be an issue.


I thought about that a bit - but in the end, I decided there were just too many different ways I'd need them to be able to change direction relatively quickly (e.g. you start or stop moving on a platform - which is the same problem, you use a switch to turn a platform on or off, someone bumps the platform you're standing on, etc).

Definitely would have been nice if I could have "game-designed" my way out of this hole =)

So it's not perfect - but I think I've got something good enough to go on with. It's using one-way LCP constraints (which are quite cool). I'll write it up in my next journal entry.

Thanks to all for your great suggestions!
November 27, 2007 08:02 AM
You must log in to join the conversation.
Don't have a GameDev.net account? Sign up!
Profile
Author
Advertisement

Latest Entries

Moose Sighting

1358 views

Constraints

1529 views

Moose

1263 views

Melon Golf

1810 views

Toon

1325 views

Spaceships

1078 views

Rendering Pt2

1170 views

Hardware Shaders

1205 views
Advertisement