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 : CharacterComponentInheritance: ParagonObject → ParagonComponent<Character> → CharacterComponent → CharacterAnimator
Remarks
CharacterAnimator bridges the gap between the character's physics-driven movement and the Animator controller. Each frame it:
Reads the character's world velocity from
CharacterMotorConverts it to local space relative to the character's transform
Normalizes it by
MoveSpeedto produce a -1..1 rangeSmoothly 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:
VelocityX
-1..1
Normalized lateral movement (strafe)
VelocityZ
-1..1
Normalized forward/backward movement
If these parameters are missing from the Animator Controller, Animator.GetFloat() / SetFloat() will silently return 0 or no-op, resulting in no animation blending.
Quick Lookup
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
AnimatorviaCharacter.GetComponentInChildren<Animator>()Gets the
CharacterMotorviaCharacter.Motor
Tick (override)
Called per-frame by the character's update loop. Updates the normalized local velocity, then applies smoothed values to the Animator.
dt
float
Delta time for this frame
Common Pitfalls
Missing Animator on character prefab
OnInitialize() searches for an Animator via GetComponentInChildren. If no Animator component exists on the character or its children, the animator field will be null, causing NullReferenceException in UpdateAnimationParameters().
Motor not initialized
CharacterMotor must be accessible via Character.Motor at initialization time. Ensure the motor component is added and initialized before the animator component.
Velocity normalization assumes MoveSpeed > 0
If Motor.MoveSpeed is zero, the normalization division will produce NaN/Infinity, corrupting animation parameters.
See Also
CharacterComponent — base class for all character services
ParagonComponent<T> — generic component base class
Last updated