Shedder
Overview
The Shedder component manages periodic or one-time spawning of items (e.g., shedded body parts) from an entity. It supports both single and batch shedding, optionally applying physics velocity to spawned items to simulate scattering. This is typically used for creatures like Bearger that shed physical objects (e.g., fur, chitin) during seasonal transitions or other game events.
Dependencies & Tags
- Relies on the presence of
TransformandPhysicscomponents on the parent entity (self.inst) for position and velocity operations. - Automatically registers a cleanup handler via
Shedder.OnRemoveFromEntity = Shedder.StopShedding, ensuring shedding stops when the component is removed from the entity.
Properties
| Property | Type | Default Value | Description |
|---|---|---|---|
inst | Entity | nil (assigned by constructor) | Reference to the host entity. |
shedItemPrefab | string? | nil | Prefab name of the item to spawn when shedding occurs. |
shedHeight | number | 6.5 | Vertical (Y-axis) position offset where shed items appear. |
shedTask | GorillaTask? | nil | Reference to the recurring periodic task; nil if shedding is inactive. |
Main Functions
StartShedding(interval)
- Description: Starts a recurring task that triggers shedding at a fixed time interval. Cancels any existing shedding task first.
- Parameters:
interval(number?, optional): Time in seconds between sheds. Defaults to60.
StopShedding()
- Description: Cancels any active periodic shedding task and clears the task reference.
DoSingleShed()
- Description: Spawns a single item at the entity’s current position, offset vertically by
shedHeightand horizontally by a small random amount (±0.5 units). Returns the spawned item instance ornilif no item could be spawned. - Parameters: None.
DoMultiShed(max, random)
- Description: Spawns multiple items (
maxcount orrandomcount ifrandomistrue) usingDoSingleShed, then applies outward physics velocity to each spawned item to scatter them radially. - Parameters:
max(number): Maximum number of items to shed.random(boolean): Iftrue, the actual number of items shed is a random integer between 1 andmax.
Events & Listeners
- Listens to entity removal via
Shedder.OnRemoveFromEntity, which is set toShedder.StopSheddingto ensure cleanup when the component is removed.