While I haven’t run out of meaty animation topics yet I want to go into a topic that is easily underestimated and that is what is commonly used to move characters around in the worlds that we build.
A collision capsule.
The character collision capsule is an approximation of the size of the character that covers their height and radius, it is generally created as a capsule that has a smooth top and bottom but I have seen solutions where this was created as a circle, cylinder, pencil or as an oriented bounding box.
We use this collision shape to drive characters around and to avoid penetration with the world and other objects and characters. So generally this shape is sitting on top of the ground and moves along it and against the world geometry and other characters.
When resolving contacts and collisions with this capsule there is generally custom weighting to the collisions so that we can make it so that one side of the contacts weigh more and can push the other object around. There are the obvious cases of a character against a wall where the resolved movement will all go to the character and push them on the plane that they are on. The capsule is also generally constrained so that there is no rotation resolve on it while there may be on the object it is colliding with.
In character movement we also want to step up on things so that contact resolve will also do additional checks whenever there is a contact to see if the character would avoid the contact if they tried to do the move from a bit higher.
There are the resolves between characters where it’s common to just split the resolve between the two characters, depending on how important it is for one character to stay at their position. For some games it is also unwanted that a character can stand on another character so it’s common to make it so that a character capsule is considered unsupported and any kind of ground check would disallowed landing on these and just keep falling.
Should also mention that in some games, generally multiplayer games it is common to allow some penetration between characters and to gently apply an impulse to separate them over time. The reason why is just to avoid harsh reactions due to network correction of replication, especially between multiple player characters.
The first trick is something we came up with at the time because we wanted to optimize our game. The physics behaviour of resolving contacts can be a costly thing in certain engines so avoiding that will avoid a lot of the cost.
I realized that this optimization also had really nice side effects that meant that it solved more than just one problem.
The trick was that instead of making the collision against the world use the entire size of the capsule we used a capsule where we cut off the feet, or the step height.
Then we used a spring to keep it at a certain height above the ground. That meant that we had a smooth movement up and down slopes. We used different spring values for moving up and down as it’s important to follow the slope downwards quicker. Small world geometry was suddenly of no importance to us as it didn’t interfere with the character movement and the springs would smoothen out any reaction to these so the character had a more stable vertical height.
Because it was a check already at step height what it also gave us was free step up behaviour so we could eliminate those additional step up collision checks.
When falling with a capsule like this you want to do your checks for landing at an offset and you will need to project the falling velocity onto this virtual ground so this is a solution that does require additional work outside of just the collision checks.
Also we want to avoid cases where the character is moving against a sloping wall that could push them down so we constrain the collision resolve to make it a vertical wall in cases where the normal of the collision plane is pointing downwards.
We still want to collide with dynamic objects and we don’t want these to generally interfere with the movement of the character unless the object is a very big object.
So we can add another capsule, this is a child collision shape that only collides with other dynamic objects and characters. This gives us the ability to collide with objects and push them around and allows us to collide with smaller characters that might go under our capsule.
In certain physics engines this works really well as the contact resolve can modify the owner of the shape. In others like the one where we originally implemented this feature we used the ragdoll collision to collide with dynamic obstacles and that was not able to send any collision response to the owner of the ragdoll as it would have been too expensive but we got highly detailed collision against dynamic objects.
The collision capsule is intended to capture the radius of the character so that we don’t allow the legs to penetrate with walls when you are walking against them. However what if you are walking along a ledge?
The capsule is checking against the ground with the full radius and thus can have the character standing in the air. I have written about the Horizon: Zero Dawn, Anthem and ‘Secret Project’ solution where the feet are pulled in to the ledge but that only works for a certain range.
There are other solutions that I’m aware of where the capsule is not allowed to walk off ledges at all and is constrained to a platform and then there are others where walking off will trigger an animation to walk off. Some do both.
To solve this additional problem of the character standing in the air we came up with a second trick and this trick is to do an additional ground check with a very small radius. If this check failed to find the ground that meant that the character was halfway off a platform.
This means we can start falling early and the falling code will just treat the surface as a surface that the character cannot stand on and will push them off.
There are side effects that you have to care for and that is getting stuck in a ditch but that can easily be detected by checking the vertical movement during falls.
A common difficulty in game character movement is judging when you will fall off those platforms so the above check that makes it connected to the legs being in air or not helps make it more deterministic but you also have cases where the player isn’t in control of the movement.
I mentioned another trick where you could allow a jump just after you start falling to give the player a grace window but there is an additional trick.
The third trick is to make the character not able to walk off the ledge as they are doing actions that they have little control over the movement distance, so attacks/etc. can then constrain the movement so that it is not allowed to move off the platform to an unsupported surface.
With the falling early detection above you should make it so that this ledge grabbing feature keeps an even smaller radius (in our case 0) so that there is a small grace window for the player if after an animation he wants to move away from the ledge. There are some actions where the feet can move so far away from the center that you may even want to make this a negative radius to keep the character on the platform with both feet.
Me too.
I’d love to know about more tricks, these are all the undocumented tricks that we put in to make games feel better and be more reliable for the player. It’s not really the stuff to do presentations on or write papers about.
But it is part of the rules for third person action games.