Unity Tutorial: Super Simple FPS Controller
This tutorial will get you a super simple (and easily modifiable) FPS Character Controller: Move with WASD, Jump with SPACE, and look around with the mouse.
Just 2 custom scripts and that's about it.
Here's a video if you prefer that format:
STEP 1: Create the objects we'll be working with
Create a new empty GameObject, name it "Player".
Drag the Camera inside. If you don't have a camera object already created, create one and drag it inside the Player object.
Left click on the Player, and create a capsule.
And finally, create an empty game object and call it "GroundCheck".
STEP 2: Align the objects
Make sure the camera is on the top end of the capsule, and that the GroundCheck is at the Player's feet.
STEP 3: Add a Character Controller to the Player Object
STEP 4: Add the "PlayerMovement" Script
Hit "Add Component" and click on "New Script"
VERY IMPORTANT: Name the script "PlayerMovement", otherwise, the code we will copy will not work.
Now double tap on the "PlayerMovement" component to bring it up on the editor.
Delete all the code that comes on by default and paste this code.
Save the code.
STEP 5: Assign the "PlayerMovement" Component values.
One of the component values is the ground layer, so we'll create that first.
Click on Layers up top and create a new layer called "Ground"
Now go ahead and configure the rest of the values.
The controller is the Character Controller above, the Ground Check is the GroundCheck gameObject, and the Ground Mask is the Ground Layer.
STEP 6: Add the "PlayerCameraMouseLook" Script
VERY IMPORTANT: Same as before, the name of the component has to be "PlayerCameraMouseLook", otherwise the code will not work.
STEP 7: Copy the "PlayerCameraMouseLook" code
Copy it from here, just like last time.
STEP 8: Fill in the "PLayerCameraMouseLook" values.
Player Body is the Player gameObject. Mouse sensitivity can be adjusted.
STEP 9: Test it out
NOTE: All surfaces the player can stand on have to be in the Layer "Ground", otherwise, you'll find that the player cannot jump.
Comments
Post a Comment