CharacterAnimator

Drives the character's Unity Animator by converting motor velocity into smoothed, normalized animation parameters (VelocityX, VelocityZ). Converts world-space velocity to local space and applies frame-rate-independent smoothing.

Definition

Namespace: Paragon.Townskeep.CharacterSystem Assembly: Townskeep.dll

[Serializable]
public class CharacterAnimator : CharacterComponent

Inheritance: ParagonObjectParagonComponent<Character>CharacterComponentCharacterAnimator

Remarks

CharacterAnimator bridges the gap between the character's physics-driven movement and the Animator controller. Each frame it:

  1. Reads the character's world velocity from CharacterMotor

  2. Converts it to local space relative to the character's transform

  3. Normalizes it by MoveSpeed to produce a -1..1 range

  4. Smoothly interpolates the Animator parameters toward the target values

The smoothing prevents jarring animation transitions when velocity changes abruptly (e.g., direction reversals, sudden stops).

Animator Parameter Contract

The target Animator Controller must have these float parameters:

Parameter
Range
Description

VelocityX

-1..1

Normalized lateral movement (strafe)

VelocityZ

-1..1

Normalized forward/backward movement

circle-exclamation

Quick Lookup

Goal
How

Set smoothing speed

Adjust smoothingSpeed in Inspector (default: 10)

Understand velocity range

Values are normalized to -1..1 by Motor.MoveSpeed

Add new animation params

Extend UpdateAnimationParameters() logic

Fields

smoothingSpeed

Controls how fast animation parameters interpolate toward the target velocity. Higher values = snappier response, lower values = smoother blending.

Methods

OnInitialize (override)

Caches the Animator and CharacterMotor references from the owning Character.

  • Finds the Animator via Character.GetComponentInChildren<Animator>()

  • Gets the CharacterMotor via Character.Motor

Tick (override)

Called per-frame by the character's update loop. Updates the normalized local velocity, then applies smoothed values to the Animator.

Parameter
Type
Description

dt

float

Delta time for this frame

Common Pitfalls

circle-exclamation
circle-exclamation
circle-exclamation

See Also

Last updated