# 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

1. 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.
2. It applies optional filters:
   * Sets vertical velocity to zero if `Horizontal Only` is checked.
   * Ignores tiny movements smaller than the `Dead Zone`.
3. It updates the Animator:
   * Calls `anim.SetFloat("MoveSpeed", speed, dampTime, Time.deltaTime)` to smoothly drive the `MoveSpeed` parameter.

***

### Example Usage

1. Add an **Animator** and assign a simple blend tree:
   * `MoveSpeed = 0` → Idle animation.
   * `MoveSpeed > 0.1` → Walk/Run blend.
2. Add **SimpleMotionAnimator** to the same GameObject.
3. Add one of:
   * **NavMeshAgent** for AI navigation.
   * **CharacterController** for player control.
   * **Rigidbody** for physics-driven characters.
4. 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.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://megacrush.gitbook.io/megacrush-unity-assets/runtime-navmesh-baker/runtime-navmesh-baker-user-manual/extras/simple-motion-animator-sample.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
