-
Book Overview & Buying
-
Table Of Contents
Creating E-Learning Games with Unity
By :
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 the PlayerControls script on the player. In the UpdateMovement() method, directly after the CharacterController.Move() method is called, declare a RayCastHit class named hitInfo 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...
Change the font size
Change margin width
Change background colour