Daily Progression: Player Setup!

addam davis
3 min readJan 12, 2022

Objective: Create an object to represent the player and a character controller!

We begin this journey as we always do, with a void. Begin by creating a cube. This cube will be the floor for our player to live on.

Flatten and stretch the cube.

Now we can create a capsule to represent the player.

Bring the player above the floor.

We need a character controller for the player.

At this point we are ready to write some code. Create a player script, attach to the player, then open the script.

We need a handle for the controller.

Remember to Null check you get components!

From here we can move on to the movement code. Create a movement method. Since this will deal with input, it needs to be with in the movement method. So have the update method call the movement method.

Since we are using a character controller, we can check if the player is grounded.

If the player is grounded, we can Get both horizontal and vertical axis.

Now we can calculate direction. Direction is a vector3 variable that consist of the two local input variables.

With this we can calculate velocity. Velocity is distance times speed.

We can check for input and jump here. Use a variable to represent how high your player can jump. Mine is set to 8f.

Now, outside of the is grounded check we want to apply gravity times Time to your player. My gravity is set to 20f.

We can now finish this off with the controller’s move function.

Now we have a functioning character controller. Go back into the editor and test your controller.

Perfect! In the next tutorial we are going to focus on having the camera follow your player through the world! I’ll see you in the next tutorial!

--

--