Animations
The animation system manages NPC animation states and transitions, allowing NPCs to display appropriate animations based on their current behavior and state.
Overview
Section titled “Overview”Located at com.hypixel.hytale.server.npc.animations
The animation system provides:
- Animation state management
- Animation transitions
- Animation synchronization with behavior
- Model-based animation control
Animation Components
Section titled “Animation Components”Core Animation System
Section titled “Core Animation System”Animations are managed through the core component system:
Located at com.hypixel.hytale.server.npc.corecomponents.audiovisual
Provides builders for:
- Animation triggers
- Animation state machines
- Sound effects
- Visual effects
Animation Builders
Section titled “Animation Builders”Located at com.hypixel.hytale.server.npc.corecomponents.audiovisual.builders
Builder pattern for creating animation components from asset data.
Model Integration
Section titled “Model Integration”Animations are tied to NPC models through the model system:
Located at com.hypixel.hytale.server.core.modules.entity.component.ModelComponent
The ModelComponent stores:
- Current model
- Animation state
- Model variants
- Visual properties
Model Assets
Section titled “Model Assets”Models are loaded from asset files:
Located at com.hypixel.hytale.server.core.asset.type.model.config.ModelAsset
Defines:
- Model geometry
- Available animations
- Animation metadata
- Skeleton structure
Animation States
Section titled “Animation States”Animation states are controlled through several mechanisms:
Movement States
Section titled “Movement States”Located at com.hypixel.hytale.protocol.MovementStates
Standard movement states that trigger animations:
- Idle
- Walking
- Running
- Jumping
- Falling
- Swimming
- Flying
- Climbing
Combat States
Section titled “Combat States”Combat-related animation states:
- Attacking
- Defending/Blocking
- Taking Damage
- Death
- Respawn
Interaction States
Section titled “Interaction States”Interaction animation states:
- Interacting with objects
- Using items
- Trading
- Dialogue poses
Custom States
Section titled “Custom States”Roles can define custom animation states through:
- State machine configurations
- Custom triggers
- Scripted sequences
Animation Triggers
Section titled “Animation Triggers”Animations can be triggered by:
Instruction Actions
Section titled “Instruction Actions”Actions within instructions can trigger animations:
// Trigger attack animationAnimationAction attackAnim = new AnimationAction("attack");attackAnim.execute(ref, role, sensorInfo, dt, store);State Changes
Section titled “State Changes”State transitions automatically trigger animations:
// Moving from idle to combat triggers combat stance animationrole.changeState("combat");Events
Section titled “Events”Specific events trigger animations:
- Damage events → hurt animation
- Death events → death animation
- Item use → use animation
Manual Triggers
Section titled “Manual Triggers”Code can manually trigger animations:
modelComponent.setAnimation("custom_animation");Animation Synchronization
Section titled “Animation Synchronization”Animations are synchronized with:
Body Motion
Section titled “Body Motion”The BodyMotion instruction component controls body animations:
- Walk/run animations match movement speed
- Turn animations match rotation
- Slope animations match terrain angle
Head Motion
Section titled “Head Motion”The HeadMotion instruction component controls head animations:
- Look direction
- Head tracking
- Independent head rotation
Actions
Section titled “Actions”Actions trigger corresponding animations:
- Attack action → attack animation
- Item use → use animation
- Interaction → interaction animation
Animation Priority
Section titled “Animation Priority”When multiple animations could play, priority determines which plays:
- Death/Critical - Highest priority
- Combat - High priority
- Interaction - Medium priority
- Movement - Low priority
- Idle - Lowest priority
Higher priority animations interrupt lower priority ones.
Animation Blending
Section titled “Animation Blending”The system supports animation blending:
- Upper body - Separate from lower body (e.g., attack while walking)
- Additive animations - Layer on top of base animations
- Transition blending - Smooth transitions between animations
Animation Configuration
Section titled “Animation Configuration”Animations are configured through:
Role Assets
Section titled “Role Assets”Role definitions specify animation behavior:
{ "animations": { "idle": "guard_idle", "walk": "guard_walk", "attack": "guard_attack", "death": "guard_death" }}Model Assets
Section titled “Model Assets”Model assets define available animations:
{ "animations": [ { "name": "guard_idle", "duration": 2.0, "loop": true }, { "name": "guard_attack", "duration": 0.5, "loop": false } ]}Core Components
Section titled “Core Components”Core component builders configure animation triggers:
{ "type": "PlayAnimation", "animation": "attack", "priority": 5}Animation Parameters
Section titled “Animation Parameters”Animations can have parameters:
- Speed - Animation playback speed
- Start time - Where in animation to start
- Loop - Whether animation loops
- Blend time - Transition duration
- Priority - Animation priority level
Animation Events
Section titled “Animation Events”Animations can trigger events at specific frames:
- Sound events - Play sounds at keyframes
- Particle events - Spawn particles during animation
- Damage events - Deal damage at specific frames
- Callback events - Trigger code at keyframes
Death Animations
Section titled “Death Animations”Death has special animation handling:
class Role { protected double deathAnimationTime; protected float despawnAnimationTime;}deathAnimationTime- Duration of death animationdespawnAnimationTime- Duration of fade-out/despawn
Death sequence:
- Trigger death animation
- Play for
deathAnimationTimeseconds - Start despawn animation
- Fade out over
despawnAnimationTimeseconds - Remove entity
Performance Considerations
Section titled “Performance Considerations”Animation Updates
Section titled “Animation Updates”Animations are updated:
- Every tick for visible NPCs
- Less frequently for distant NPCs
- Not at all for off-screen NPCs
LOD (Level of Detail)
Section titled “LOD (Level of Detail)”Animation complexity scales with distance:
- Close - Full animation with blending
- Medium - Simplified animation
- Far - Static pose or no animation
Animation Caching
Section titled “Animation Caching”- Cache animation state to avoid recalculation
- Reuse animation data across similar NPCs
- Pool animation objects
Debugging Animations
Section titled “Debugging Animations”Tools for debugging animations:
- Visual animation state display
- Animation transition logging
- Frame-by-frame playback
- Animation timeline view
Integration with Client
Section titled “Integration with Client”The server sends animation state to clients:
- Current animation name
- Animation time/progress
- Animation parameters
- Transition state
Clients interpolate and render animations locally.
Best Practices
Section titled “Best Practices”- Use standard states - Leverage built-in movement/combat states
- Test transitions - Ensure smooth animation transitions
- Set appropriate durations - Match animation length to action duration
- Use priorities - Prevent animation conflicts
- Optimize distant NPCs - Reduce animation updates for far NPCs
- Avoid rapid changes - Prevent animation flickering
Common Patterns
Section titled “Common Patterns”Walk Animation
Section titled “Walk Animation”// Automatically triggered by movement// Speed scales with movement speedif (moving) { animation = isRunning ? "run" : "walk"; animationSpeed = movementSpeed / baseSpeed;}Attack Animation
Section titled “Attack Animation”// Triggered by attack action// Damage dealt at specific frameattackAction.trigger();// → plays "attack" animation// → frame 15: deal damage// → return to idleState-Based Animation
Section titled “State-Based Animation”// Animation changes with NPC stateswitch (currentState) { case IDLE: animation = "idle"; break; case ALERT: animation = "alert"; break; case COMBAT: animation = "combat_stance"; break; case FLEE: animation = "flee"; break;}Layered Animation
Section titled “Layered Animation”// Upper body independent from lower bodylowerBody.setAnimation("walk");upperBody.setAnimation("attack");// Result: attacking while walkingRelated Systems
Section titled “Related Systems”- Roles - Configure animation behavior
- Instructions - Trigger animations
- Model System - Defines available animations
- Entity System - Stores animation state