To make our game character move through the level more smoothly, we will modify the motion algorithm. Instead of relying on gravity on the rigid body to keep the player anchored to the ground, we will cast a ray downward and glue the player to the polygon directly below. In this way, the curvature of the terrain will play less of a role in restricting the player. This can be achieved by performing the following steps:
Switch to the
MAIN
scene, and double click on thePlayerControls
script on the player. In theUpdateMovement()
method, directly after theCharacterController.Move()
method is called, declare aRayCastHit
class namedhitInfo
as shown in the following code. This class will be used to return the position of the polygon from a raycast that is directly below the player. By invoking a raycast downward, we can check what other GameObject is intersected and use this information to glue the player to the ground directly at the point of contact:RayCastHit...