# Character Prefab Pattern

This manual explains how player character prefabs should be built. In this project, the main player character is Rika.

## Current Character Prefab

Path:

```text
Assets/Prefabs/Characters/Rika.prefab
```

Main scripts:

```text
Assets/Scripts/Player/RikaPlayerController.cs
Assets/Scripts/Player/PlayerShooter.cs
Assets/Scripts/Player/PlayerFuel.cs
Assets/Scripts/Player/PlayerRespawn.cs
```

Animations:

```text
Assets/Animations/Player/Rika
```

## Expected Structure

Rika should be a root prefab with helper children.

```text
Rika
└── FirePoint
```

The root `Rika` object owns the body, physics, animator, and player scripts.

`FirePoint` is only a spawn position for bullets.

## Required Components

Rika root should have:

```text
Transform
SpriteRenderer
Animator
Rigidbody2D
CapsuleCollider2D
RikaPlayerController
PlayerShooter
PlayerRespawn
PlayerFuel
```

## Component Responsibilities

```text
Transform            = world position, scale, child setup
SpriteRenderer       = visual sprite and flip direction
Animator             = animation controller
Rigidbody2D          = physics movement
CapsuleCollider2D    = player body collision
RikaPlayerController = movement, jump, dash, hit response
PlayerShooter        = player projectile spawning
PlayerRespawn        = fall death and checkpoint respawn
PlayerFuel           = health/fuel value
```

## Rigidbody2D Rules

Rika should use a `Rigidbody2D` because movement uses physics velocity.

Recommended:

```text
Body Type: Dynamic
Gravity Scale: enabled
Freeze Rotation Z: enabled
```

Why freeze rotation:

```text
Rika should not spin after collisions.
```

## Collider Rules

Rika uses a body collider, currently a `CapsuleCollider2D`.

The collider should:

```text
Cover the body
Not be too wide
Touch the ground reliably
Not include weapon or bullet range
```

Attack range and projectile spawning should not be part of Rika's body collider.

## Animator Rules

Rika uses:

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

Important states include:

```text
Idle
Run / Walk
Jump
Dash / Sprint
Attack
Hit
```

Scripts should trigger animation parameters. They should not manually swap sprites.

## FirePoint Rules

`FirePoint` is a child GameObject.

Example:

```text
Rika
└── FirePoint
```

It should be placed in front of Rika's body.

Use:

```text
PlayerShooter.firePoint
```

Do not make the bullet prefab a permanent child of Rika.

Correct:

```text
Press attack
PlayerShooter instantiates Rika_Bullet prefab at FirePoint
Bullet moves by its own script
```

## PlayerShooter References

`PlayerShooter` needs:

```text
Bullet Prefab -> Assets/Prefabs/Combat/Rika_Bullet.prefab
Fire Point -> Rika/FirePoint
Visual Sprite Renderer -> Rika SpriteRenderer
```

If these are missing, shooting may fail or bullets may spawn in the wrong place.

## Fuel And Respawn Pattern

Rika's health system is called Fuel.

```text
PlayerFuel
```

Fuel is restored by:

```text
RestCheckpoint
```

Respawn is handled by:

```text
PlayerRespawn
Checkpoint
```

Important behavior:

```text
When Rika rests at fire_camp, fuel refills and checkpoint is saved.
When Rika falls below death height, she respawns at the current checkpoint.
```

## Dash Pattern

Dash is owned by:

```text
RikaPlayerController
```

Current rules:

```text
Dash is horizontal.
Dash sets vertical velocity to 0 during dash.
Dash disables gravity during dash.
Dash can be used once in the air.
Dash is invincible.
Dash ignores solid enemy colliders.
```

Dash values are on `RikaPlayerController`:

```text
Dash Speed
Dash Duration
Dash Cooldown
```

## Hit Pattern

Rika hit behavior uses:

```text
PlayerFuel.TakeDamage(...)
RikaPlayerController.TryStartHitResponse(...)
```

Current behavior:

```text
Damage reduces Fuel.
Hit animation plays.
Rika gets short invincibility.
Rika is knocked back from damage source.
```

Tune on `RikaPlayerController`:

```text
Hit Invincible Duration
Hit Knockback Horizontal Force
Hit Knockback Vertical Force
Hit Movement Lock Duration
```

## Sorting Layer

Rika should be on:

```text
Sorting Layer: Characters
Order in Layer: 0
```

If Rika appears behind ground or props, check the SpriteRenderer sorting settings.

## Checklist For Editing Rika

Before committing changes:

```text
Rika prefab opens without missing scripts
Animator Controller is assigned
Rigidbody2D exists and rotation is frozen
CapsuleCollider2D matches body
PlayerShooter references bullet prefab and FirePoint
PlayerFuel exists
PlayerRespawn exists
FirePoint is correctly placed
Sorting Layer is Characters
Jump, dash, shoot, hit, respawn all work in Play Mode
```

## Summary

The player prefab pattern is:

```text
One root character prefab
Physics and visuals on the root
Small child objects for helper points
Focused player scripts as components
Reusable projectile prefab spawned at runtime
```
