How to Make a Player Move in Unity Using the Mouse
Getting a player character to follow or respond to mouse input is one of the most common mechanics in Unity game development — and one of the most varied. Whether you're building a top-down RPG, a point-and-click adventure, or a 3D shooter, "mouse movement" in Unity can mean several very different things depending on your game's perspective, physics setup, and intended feel.
What "Mouse Movement" Actually Means in Unity 🖱️
Before writing a single line of code, it helps to identify which type of mouse-driven movement you actually need. There are three primary patterns:
- Click-to-move — the player clicks a destination and the character walks there
- Mouse-look rotation — the player character or camera rotates to face the mouse cursor
- Mouse-drag or direct following — the object moves continuously toward or with the cursor
Each requires a meaningfully different implementation in Unity, and mixing them up is one of the most common sources of confusion for new developers.
Core Unity Concepts You'll Use
Regardless of which approach you take, mouse movement in Unity relies on a few foundational systems:
Input.mousePosition returns the mouse's position in screen space — pixel coordinates relative to the bottom-left corner of the game window. This is raw screen data, not world data.
Camera.main.ScreenToWorldPoint() converts that screen-space position into a world-space coordinate your GameObjects can actually use.
Camera.main.ScreenPointToRay() casts an invisible ray from the camera through the mouse cursor into the 3D scene — essential for click-to-move and raycast-based targeting.
Understanding the difference between screen space and world space is probably the single most important concept here. Most movement bugs in beginner Unity projects come from using one when the code expects the other.
Method 1: Click-to-Move (Top-Down or Isometric)
This is the classic MOBA or CRPG control scheme. The player clicks a point on the ground, and the character navigates there.
The general approach:
- Cast a ray from the camera through the mouse position using
Physics.Raycast - Detect what the ray hits — typically a ground plane or NavMesh surface
- Pass the hit point to a NavMesh Agent or manually interpolate the character's position toward that point
Unity's NavMesh system handles pathfinding automatically once baked. You set navMeshAgent.SetDestination(hitPoint) and the agent navigates around obstacles on its own.
For projects without NavMesh, you can move the character using Vector3.MoveTowards() or transform.position = Vector3.Lerp(...) each frame, though this won't handle obstacle avoidance.
Key variable: whether your game is 2D or 3D changes this significantly. In 2D, you'll use Physics2D.Raycast and work in the XY plane rather than XZ.
Method 2: Mouse-Look (Character or Camera Rotation)
In top-down shooters and twin-stick-style games, the player character rotates to always face the mouse cursor.
The general logic:
- Get the mouse position in world space
- Calculate the direction vector from the player to that world position
- Rotate the character using
Quaternion.LookRotation()orMathf.Atan2()for 2D
For 3D mouse-look, you typically project the mouse position onto a horizontal plane at the player's Y height, then rotate the character's Y-axis toward that point.
For 2D mouse-look, Mathf.Atan2(direction.y, direction.x) gives you the angle in radians, which you convert to degrees and apply as a Z-axis rotation.
A common pitfall: forgetting to account for the camera's angle. A top-down camera tilted at 45 degrees will give different world-space projections than one directly overhead, and your rotation math needs to compensate.
Method 3: Object Follows the Mouse Cursor Directly
Used in games where a player-controlled object tracks the cursor in real time — common in casual games, cursor-based puzzles, or when controlling a targeting reticle.
The approach is simpler: every frame, convert the mouse's screen position to world space and move the object there using transform.position or by setting a Rigidbody velocity toward the target.
Rigidbody vs. Transform movement is an important distinction:
| Approach | Best For | Tradeoffs |
|---|---|---|
transform.position | Simple, non-physics objects | Ignores physics collisions |
Rigidbody.MovePosition() | Physics-enabled objects | Respects colliders, more stable |
velocity targeting | Smooth pursuit movement | Requires tuning drag/force values |
If your player has a Rigidbody component and you move it via transform.position directly, you'll often see jittery collision behavior or objects clipping through walls.
Variables That Determine Your Approach 🎮
Several factors shift which implementation makes sense:
- 2D vs. 3D project — coordinate systems, physics components, and camera projection all differ
- Camera perspective — orthographic cameras (common in 2D) simplify screen-to-world math; perspective cameras require plane intersection math
- Physics setup — whether your character uses a Rigidbody, CharacterController, or neither changes how movement should be applied
- Pathfinding needs — click-to-move with obstacles almost always benefits from NavMesh rather than direct interpolation
- Input System version — Unity's older
Inputclass vs. the newer Input System package use different APIs, and mixing them causes silent failures
The Newer Input System
Unity's Input System package (as opposed to the legacy Input class) handles mouse position through Mouse.current.position.ReadValue(). If your project uses this package, legacy Input.mousePosition calls won't work unless the compatibility layer is enabled in Project Settings.
Checking which input system your project is configured to use — found under Edit → Project Settings → Player → Active Input Handling — is worth doing before writing any input code.
What works cleanly for a simple 2D prototype with an orthographic camera and no physics may need substantial rethinking the moment you add a perspective camera, a Rigidbody, or a 3D environment with uneven terrain. The specific combination of those factors in your project is what determines which approach — and which edge cases — actually apply to you.