# Animation Workflow

This manual explains how animation should be handled in the project.

## Animation Assets

Animation files live under:

```text
Assets/Animations
```

Current groups:

```text
Assets/Animations/Player/Rika
Assets/Animations/Enemies/Monster
Assets/Animations/Enemies/Wizard
Assets/Animations/Bosses/AshenTitan
Assets/Animations/Others
```

## Core Pieces

Unity animation usually has:

```text
Sprite frames
Animation clip (.anim)
Animator Controller (.controller)
Animator component
Script triggers/parameters
```

Example:

```text
Rika sprite frames
-> Rika_Run.anim
-> Rika.controller
-> Animator component on Rika.prefab
-> RikaPlayerController sets animator parameters
```

## Animation Clips

Animation clips store frame changes over time.

Examples:

```text
Rika_Idle.anim
Rika_Run.anim
Rika_Hit.anim
Monster_Attack.anim
Monster_Death.anim
Wizard_Attack.anim
fire_camp.anim
```

Naming rule:

```text
CharacterName_Action.anim
```

Good:

```text
Rika_Hit.anim
Monster_Attack.anim
Wizard_Death.anim
```

## Animator Controllers

Animator Controllers decide which clip plays.

Examples:

```text
Rika.controller
Monster.controller
Wizard.controller
fire_camp.controller
```

Animator Controller belongs on the prefab's `Animator` component.

## Script-To-Animator Pattern

Scripts should set Animator parameters.

Examples:

```csharp
animator.SetTrigger("Attack");
animator.SetTrigger("Death");
animator.SetBool("IsGrounded", true);
animator.SetFloat("MoveSpeed", speed);
```

Do not manually swap sprites from gameplay scripts unless there is a very specific reason.

## Current Rika Animation Pattern

Rika uses:

```text
Assets/Animations/Player/Rika/Rika.controller
```

Controlled by:

```text
RikaPlayerController
```

Common parameters:

```text
MoveSpeed
IsGrounded
Dash
Attack
Hit
```

## Current Enemy Animation Pattern

Monster and Witch use:

```text
MonsterAnimator
MonsterContactAttack
EnemyHealth
```

Attack:

```text
MonsterContactAttack.TryAttack()
-> MonsterAnimator.PlayAttack()
-> Animator Attack trigger
```

Death:

```text
EnemyHealth.Die()
-> MonsterAnimator.PlayDeath()
-> Death animation plays immediately
```

Death must have priority over attack.

## Animation Events

Animation events call script methods at exact frames.

Current use:

```text
Monster_Attack.anim
-> EnableAttackHitbox()
-> DisableAttackHitbox()

Wizard_Attack.anim
-> EnableAttackHitbox()
-> ShootBullet()
-> DisableAttackHitbox()
```

Use animation events when gameplay timing must match animation frames.

Good uses:

```text
Enable attack hitbox
Disable attack hitbox
Shoot projectile
Play footstep sound
Spawn visual effect
```

Avoid putting large gameplay logic directly in animation events. Use the event to call a small method.

## Attack Animation Rules

For attack animations:

```text
Attack state should be entered by trigger.
Damage should only happen during active frames.
Hitbox should be enabled/disabled by animation events.
Attack should return to idle/walk after completion.
```

For Wizard:

```text
Facing direction locks when attack starts.
Projectile direction should match locked facing direction.
```

## Death Animation Rules

Death should override other actions.

Current project rule:

```text
When enemy dies:
Attack trigger is reset.
Death trigger is set.
Death state plays immediately.
Attack behavior is disabled.
Shooter behavior is disabled.
```

Death animation should not transition back to idle or attack.

## Sprite Size Rules

Keep frame sizes consistent inside one animation set.

Example problem:

```text
Idle frames are 128x128.
Attack frames are 931x931.
```

This causes scale and collider confusion.

Preferred:

```text
Resize/prepare frames before making clips.
Use consistent pixel size and pivot.
```

## Pivot Rules

Sprite pivot affects visual alignment.

If an animation appears to jump, slide, or sink:

```text
Check sprite pivot
Check frame size
Check pixels per unit
Check animation clip position curves
Check prefab scale
```

## Animator Debug Checklist

If animation does not play:

```text
Animator component exists
Animator Controller is assigned
Parameter name is spelled correctly
Script sets correct trigger/bool/float
Transition condition exists
Transition is not blocked by exit time
State has correct animation clip
Animation clip has frames
Prefab uses correct controller
```

If animation keeps playing wrong state:

```text
Check Any State transitions
Check exit time
Check transition duration
Check trigger reset
Check death priority
```

## Summary

Animation workflow:

```text
Prepare sprites
Create animation clips
Create Animator Controller
Add Animator to prefab
Drive parameters from scripts
Use animation events for timed gameplay windows
Test in Play Mode
```
