Here’s a simple, yet robust FPS‐style controller using Unity’s built‑in CharacterController. Just drop this on your “Player” GameObject (with a CharacterController component) and assign your Camera in the inspector. 🎮
csharp
using UnityEngine;
[RequireComponent(typeof(CharacterController))]
public class SimpleFPSController : MonoBehaviour
{
[Header("References")]
[Tooltip("Reference to the player camera")]
public Camera playerCamera;
[Header("Movement")]
public float moveSpeed = 6f;
public float jumpHeight = 1.5f;
public float gravity = -9.81f;
[Header("Mouse Look")]
public float lookSensitivity = 2f;
public float maxLookAngle = 80f;
// private
CharacterController cc;
Vector3 velocity;
float cameraPitch = 0f;
void Start()
{
cc = GetComponent<CharacterController>();
Cursor.lockState = CursorLockMode.Locked;
}
void Update()
{
HandleMouseLook();
HandleMovement();
}
void HandleMouseLook()
{
// Read mouse deltas
float mouseX = Input.GetAxis("Mouse X") * lookSensitivity;
float mouseY = Input.GetAxis("Mouse Y") * lookSensitivity;
// Yaw rotation (player body)
transform.Rotate(Vector3.up * mouseX);
// Pitch rotation (camera)
cameraPitch -= mouseY;
cameraPitch = Mathf.Clamp(cameraPitch, -maxLookAngle, +maxLookAngle);
playerCamera.transform.localEulerAngles = Vector3.right * cameraPitch;
}
void HandleMovement()
{
// Ground check
if (cc.isGrounded && velocity.y < 0)
velocity.y = -2f; // small downward force to keep grounded
// Input
float x = Input.GetAxis("Horizontal");
float z = Input.GetAxis("Vertical");
// Move in local space
Vector3 move = transform.right * x + transform.forward * z;
cc.Move(move * moveSpeed * Time.deltaTime);
// Jump
if (Input.GetButtonDown("Jump") && cc.isGrounded)
{
velocity.y = Mathf.Sqrt(jumpHeight * -2f * gravity);
}
// Apply gravity
velocity.y += gravity * Time.deltaTime;
cc.Move(velocity * Time.deltaTime);
}
}
How to set it up
Create an empty Player GameObject.
Add a CharacterController component.
Create a child Camera (named “PlayerCamera”) and position it at eye‐level.
Attach the SimpleFPSController script to “Player”.
Drag your Camera into the script’s Player Camera slot.
Tweak Move Speed, Jump Height, Look Sensitivity in the Inspector.
Make sure your Input settings (Edit ▶️ Project Settings ▶️ Input Manager) have “Horizontal”, “Vertical”, “Mouse X”, “Mouse Y” and “Jump” defined (these come by default in new projects).
Now hit Play ▶️ and you should be strafing, jumping, and looking around like a classic FPS! 🎯
Tips & Extensions
• Add “sprint” by multiplying moveSpeed when the Shift key is held.
• Smooth crouch by shrinking the CharacterController’s height.
• Head‑bob, weapon sway, footstep sounds, etc., for extra polish.
Enjoy building your shooter! 🚀 Let me know if you need networking, recoil, or other features.