Mouse Virtual Joystick
Generates a virtual 2D joystick value from mouse movement.
This action accumulates mouse delta into an internal “stick” value, applies a dead zone and optional spring-back (recentering), and outputs a Vector2 value.
It can also optionally drive a UI handle (e.g., a joystick thumb image) to visualize the input.
Overview
Use Mouse Virtual Joystick when you want mouse movement to behave like an analog stick:
- Move the mouse → the virtual stick is pushed in that direction.
- Stop moving the mouse → the stick can slowly recentre, like a spring.
- The output is a Vector2 with dead zone, clamping, inversion, and scaling.
Typical uses:
- Twin-stick aiming with mouse
- Top-down shooters (movement with WASD, aim with virtual stick)
- Flight/space “mouse-as-stick” controls
- UI radial menus with directional selection
The action updates every frame by default.
Input Setup
You must provide an Input Action that outputs pointer delta, commonly:
<Pointer>/delta<Mouse>/delta
Assign that action to Mouse Delta Action.
Ensure the action (or its map/asset) is enabled via PlayerInput or an InputActionMapEnable action.
Action Fields
Input
| Field | Description |
|---|---|
| Mouse Delta Action | InputActionReferenceVar providing pointer/mouse delta (Vector2). |
Tuning
| Field | Description |
|---|---|
| Sensitivity | Multiplier from mouse delta (pixels) to internal stick movement. Default: 0.002. |
| Return Rate | Speed that the stick springs toward zero when recentering. 0 means no spring. Default: 1.5. |
| Recenter Threshold | Stick magnitude threshold [0..1] below which springing activates. 0 = always spring. Default: 0.35. |
| Dead Zone | Radius near center where output is zero. Helps remove jitter. Default: 0.1. |
| Clamp Magnitude | If true, prevents internal stick from exceeding magnitude 1. |
Controls
| Field | Description |
|---|---|
| Invert X | Optional inversion of horizontal axis. |
| Invert Y | Optional inversion of vertical axis. |
| Multiplier | Optional per-axis multiplier applied after invert & dead zone. Useful for tuning X/Y sensitivity independently. |
Output
| Field | Description |
|---|---|
| Value | The final virtual joystick output as a Vector2. |
| Magnitude | Optional normalized magnitude (0..1) after dead zone but before invert/multiplier. |
UI (Optional)
| Field | Description |
|---|---|
| UI Handle | RectTransform of a joystick “thumb”. Must be centered at anchoredPosition (0, 0). |
| UI Max Radius | Max visual radius for full deflection. 0 = auto-use half of parent size. |
| Rotate Handle | If true, rotates handle so its local “up” direction points away from center. |
Tips
Sensitivity
- Lower sensitivity → slow stick movement, good for fine control.
- Higher sensitivity → fast stick movement, more responsive.
Dead Zone
- Typical values:
0.1–0.2to clean up micro-movements. - Larger values create a more noticeable “flat” response.
Return Rate + Recenter Threshold
- Return Rate = 0 → no spring: the stick only moves when the mouse moves.
- Recenter Threshold = 0 → always apply spring.
- Threshold > 0 → only spring near center for a “looser” outer range.
UI Handle
A simple setup:
- A background ring (Image)
- A child “handle” Image at anchoredPosition (0,0)
- Assign that child as UI Handle
- Use a small UI Max Radius or allow auto radius
Example: Top-Down Aiming
-
Create an InputAction:
- Name:
MouseDelta - Type: Value (Vector2)
- Binding:
<Pointer>/delta
- Name:
-
Enable the action via PlayerInput or an InputActionMapEnable action.
-
Add Mouse Virtual Joystick to your FSM:
- Mouse Delta Action:
MouseDelta - Sensitivity:
0.002 - Return Rate:
1.5 - Threshold:
0.35 - Dead Zone:
0.1 - Output:
AimStick
- Mouse Delta Action:
-
Use
AimStickto:- Rotate the player
- Move a reticle
- Determine shooting direction