Pages

Monday, July 15, 2019

The Footbase - Improving Foot Constraints

In addition to correctly restraining the joint angles during motion, for added realism a model’s feet should match the surface angle of the terrain. Currently only the heel joint is used to check the contact with the floor, which may cause the rest of the foot to clip through the ground/obstacles during the support phase.

Johansen (2009) explains that simply using a single joint/point on the foot is insufficient to orient the joints of the feet to the surface appropriately, as shown in figure 1.

Figure 1: Foot clipping with environment when single joint used to compare ground plane (Johansen, 2009)

Johansen (2009) presents a solution to this issue – the footbase.


The footbase is always perpendicular to the surface beneath it and acts as a walkable surface to which the feet of the model can be oriented.

Figure 2: Footbase used to orient foot, preventing intersection with environment (Johansen, 2009)

Application in my solution 

Using the above method as a basis for my own solution, I developed a system that would use the surface normal of any walkable surface to correctly orient the foot.

To do this, I raycast below each foot from 3 locations – the heel, the ball of the foot and the toes (as shown in figure 3).

Figure 3: Raycasts to determine walkable surface normal values

If the ground surface is within range of the raycast, the surface normal at each raycast hit point are taken and the average found. The rotation of the heel, ball of the foot and toe joints are then set equal to that of the average normal.
This keeps the foot parallel to the ground surface regardless of the ground orientation.

While this approach was functional, the resulting behaviour was unnatural with joints snapping to new rotations. I also found that the applying the average surface normal to the foot joints still occasionally caused the toe joint to intersect with obstacles.

To improve these behaviours, I adjusted how the corrective rotation was applied, using spherical linear interpolation.

Figure 4: Corrective rotation applied smoothly using interpolation

This smooths the rotation over time by returning a proportional value between the current and desired rotation, determined by the ‘rotateSpeed’ variable. This eliminated the angular snapping.

To avoid the toe clipping problem I revised the logic of how the corrective angles are determined.
The heel and ball of the foot are treated as one object, and the toes another. If the heel or ball of the foot raycasts detect the ground surface normal, the rotations of both joints are set to the surface normal (this adjustment will also bring the other joint raycast in contact with the ground surface). If both detect the ground surface normal then an average is taken and both joint rotations are adjusted to match this value.
The toe joint rotation is updated independently of the heel and ball of the foot joints. This allows the toe to bend and fit to the normal of any obstacle, rather than clip through it – replicating the natural action of the human foot.

Figure 5: Adjusting foot joint rotations to mirror supporting surfaces

While the feet now rotate to match the ground normal, if the ground plane is raised there is no reaction to obstacles that may intersect the legs limbs (shown in figure 6). As the feet rotate to meet the surface normal of higher gradient slopes there is also a high chance that one or more of the raycasts fail to meet the surface, leaving the rotation applied not suitable for the surface, causing clipping.

Figure 6: Unable to accomodate limb intersections or steep surface normals

To adapt to this, a raycast is sent from the hip to knee joint, then the knee to heel joint of each leg limb. If a collider intersects the raycast, the hit point is set as the target of the CCD solution, raising the leg to meet the surface.

Figure 7: Full behaviour to avoid limb intersections while adjusting foot joint rotations to mirror supporting surfaces

Note that the model I have sourced has the heel joint approximately where the ankle joint would usually be located. This causes the target seeking behaviour to position the heel of the foot slightly below the surface of the intersecting object when using this model.


Given that I was unsuccessful in constraining joint rotation angles using CCD, the leg limbs reactions to the intersecting plane will very rarely appear natural.
With functional constraints this behaviour would appear natural as the leg limbs seek the updated CCD targets.


References
Johansen, R. (2009). Dynamic Walking with Semi-Procedural Animation, Unity Technologies. San Francisco. Available at: https://www.gdcvault.com/play/966/Dynamic-Walking-with-Semi-Procedural [Accessed 11 Jul. 2019]

Bilbiography
Unity Technologies (2018). Unity - Scripting API: Quaternion.Slerp. [online] Docs.unity3d.com. Available at: https://docs.unity3d.com/ScriptReference/Quaternion.Slerp.html [Accessed 11 Jul. 2019].

Unity Technologies (2018). Unity - Scripting API: Quaternion.FromToRotation. [online] Docs.unity3d.com. Available at: https://docs.unity3d.com/ScriptReference/Quaternion.FromToRotation.html [Accessed 12 Jul. 2019].