Simple Motion Animator (Sample)
Namespace: MegaCrush.Spawner.Samples
The SimpleMotionAnimator is a lightweight helper script that drives an Animator’s MoveSpeed
parameter based on the object’s velocity. It works automatically with a variety of movement systems:
NavMeshAgent
CharacterController
Rigidbody
Or just transform position deltas (fallback).
This makes it ideal for quickly hooking up characters in sample scenes (enemies, NPCs, or the player) without needing a custom animation controller.
Inspector
Damp Time (float) How quickly the animator parameter blends toward the new value (smoothing).
Horizontal Only (bool) If enabled, ignores vertical velocity (useful for grounded movement).
Dead Zone (float) Threshold below which small jitter is ignored and treated as zero.
Animator Setup
The script expects an Animator component on the same GameObject, with a float parameter named:
MoveSpeed
You can use this parameter in blend trees or transitions (e.g., idle ↔ walk ↔ run).
How It Works
At runtime, the script detects which movement component is present:
NavMeshAgent: uses
agent.velocity
.CharacterController: uses
cc.velocity
.Rigidbody: uses
rb.velocity
.Fallback: calculates velocity from
transform.position
delta.
It applies optional filters:
Sets vertical velocity to zero if
Horizontal Only
is checked.Ignores tiny movements smaller than the
Dead Zone
.
It updates the Animator:
Calls
anim.SetFloat("MoveSpeed", speed, dampTime, Time.deltaTime)
to smoothly drive theMoveSpeed
parameter.
Example Usage
Add an Animator and assign a simple blend tree:
MoveSpeed = 0
→ Idle animation.MoveSpeed > 0.1
→ Walk/Run blend.
Add SimpleMotionAnimator to the same GameObject.
Add one of:
NavMeshAgent for AI navigation.
CharacterController for player control.
Rigidbody for physics-driven characters.
Press Play — the Animator will automatically blend animations based on actual movement.
Why It’s Useful
Works with multiple movement systems out of the box.
Prevents “feet sliding” by basing animation on actual velocity.
Provides simple smoothing and jitter filtering.
Minimal setup: just add
MoveSpeed
to your Animator.
This makes a perfect companion to the ClickToMoveController in the samples:
ClickToMoveController
moves the NavMeshAgent.SimpleMotionAnimator
drives the animations based on the agent’s velocity.
Last updated