Skip to content

StixKnowledge/unity-player-controller-new-input-system

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 

Repository files navigation

Unity Player Controller

A simple and beginner-friendly Player Controller for Unity using the New Input System.
This controller includes smooth movement, mouse look, jumping, gravity handling, and camera rotation using CharacterController.

Perfect for:

  • FPS Games
  • Third-Person Prototypes
  • Horror Games
  • Sandbox Projects
  • Beginner Unity Projects

Features

✔ WASD Movement
✔ Mouse Look Rotation
✔ Jumping System
✔ Gravity Handling
✔ Camera Rotation Clamp
✔ CharacterController Support
✔ Cursor Lock for Gameplay Feel
✔ Beginner-Friendly Code Structure


Requirements

  • Unity 2021 or newer
  • Unity Input System Package
  • CharacterController Component

Installation

1. Install the Input System

Open:

Window → Package Manager

Search for:

Input System

Install the package.


2. Enable the New Input System

Open:

Edit → Project Settings → Player

Under:

Active Input Handling

Select:

  • Both or
  • Input System Package (New)

Unity will ask to restart the editor.

Restart Unity.


Player Setup

1. Create the Player Object

Create an empty GameObject and rename it:

Player

Add the following components:

  • CharacterController
  • PlayerController Script
  • PlayerInput

2. Create the Camera

Create a Camera as a child of the Player object.

Hierarchy Example:

Player
└── Main Camera

Assign the Camera Transform to:

cameraTransform

inside the PlayerController Inspector.


Using Unity's Default Input Actions

Unity already provides default actions for:

  • Move
  • Look
  • Jump

through the Starter Assets or Default Input Actions setup.

You can use those instead of manually creating new actions.


Player Input Setup

1. Select the Player GameObject

In the Inspector, locate the:

Player Input

component.


2. Assign the Input Actions Asset

Drag your existing Input Actions asset into the:

Actions

field.


3. Set Default Action Map

Set:

Default Map = Player

4. Set Behavior

Set:

Behavior = Invoke Unity Events

Connecting Events

Open:

Events → Player

You will see the default actions:

  • Move
  • Look
  • Jump

Move Event

  1. Click the + button
  2. Drag the Player GameObject into the object field
  3. Select:
PlayerController → OnMove

Look Event

  1. Click the + button
  2. Drag the Player GameObject into the object field
  3. Select:
PlayerController → OnLook

Jump Event

  1. Click the + button
  2. Drag the Player GameObject into the object field
  3. Select:
PlayerController → OnJump

Final Setup Checklist

✔ CharacterController attached
✔ PlayerController script attached
✔ PlayerInput component attached
✔ Input Actions asset assigned
✔ Default Action Map set to Player
✔ Camera assigned to cameraTransform
✔ Move event connected
✔ Look event connected
✔ Jump event connected


Controls

Action Key
Move WASD
Look Mouse
Jump Space

How It Works

Movement

The script uses:

CharacterController.Move()

for smooth movement based on player direction.


Jumping

Jump force is calculated using the physics formula:

v = √(jumpHeight × -2 × gravity)

This creates a cleaner and more realistic jump.


Mouse Look

  • Horizontal mouse movement rotates the player
  • Vertical mouse movement rotates the camera
  • Camera rotation is clamped to prevent over-rotation

Script Preview

CharacterController.Move(move * moveSpeed * Time.deltaTime);

Future Improvements

  • Sprint System
  • Crouch System
  • Head Bobbing
  • Footstep Sounds
  • Interaction System
  • Stamina System

License

Free to use for personal and commercial projects.


Author

Created by Stix&Kno

About

A simple and beginner-friendly Player Controller for Unity using the New Input System. This controller includes smooth movement, mouse look, jumping, gravity handling, and camera rotation using `CharacterController`.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages