Nerd For Tech
Published in

Nerd For Tech

Character Movement with Character Controller

3rd Person Zombie Shooter

Objective: Allow player to move using Character Controller

First of all add a Character controller component to the player and remove its collider.

Now create a reference variable for character controller and float variable for speed, jump height, gravity and yVelocity for the player movement.

Assign the reference to the created Character controller variable inside the start function.

Now create a new function to store the player behavior. Inside it create two float variable which stores the horizontal movement and vertical movement value respectively.

Then create a direction vector and create its velocity which is direction multiplied by speed.

Then check if the player is grounded and then check if the space key is pressed. if true then store the jump height value to yVelocity and if the player is not grounded the apply gravity by subtracting the gravity value with yVelocity.

Change the y-axis in original velocity vector with yVelocity so that player jumps, falls according to the logic.

Now transform the velocity from local space to world space and move the player through character controller.

And this is the final result.



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store