This repository documents the creation of a player movement script in Unity, broken down into multiple parts. Part 1 includes basic walking, camera control, and jumping mechanics. Future updates will introduce more advanced features as I refine and expand the script. Stay tuned for ongoing improvements and additional functionalities!
To set up the project hierarchy:
-
Create an Empty Parent Object:
- Name it
CameraHolder. - Place the
MainCamerainside this parent and rename it as desired.
- Name it
-
Create the empty Player Object:
- Create an empty object named
Player. - Attach a
Rigidbodycomponent to thePlayerobject (set it toContinuousandInterpolate).
- Create an empty object named
-
Add Player Components:
- Inside the
Playerobject, create a capsule and attach aCapsule Collidercomponent. Name itPlayerObj. - Add two more empty objects as children of the
Playerparent.
- Inside the
-
Positioning:
- Position the
CameraHolderandCameraPosat the top of the player’s head.
- Position the
-
Create a Ground Layer:
- Create a new layer called
Ground. - Apply this layer to all objects you want the player to stand or jump on.
- Create a new layer called
This script ensures that the camera follows the player.
- Attach this script to the
CameraHolder.
The PlayerCam script handles the camera controls in the game. Here's how it works:
-
X-axis Rotation: Both the camera and the player's body rotate.
-
Y-axis Rotation: Only the camera rotates, keeping the player's body stationary.
-
Attach this script to the main camera as shown below:
This script manages the player's movement and interactions.
- Attach this script to the
Playerobject (the parent with theRigidbodycomponent). - Optional: Add a physics material with low settings to the player's body for better movement.
You can adjust the game's gravity in Unity's settings for better physics interactions.



