Enemy NPC Player Detection - UQcsse3200/2024-studio-2 GitHub Wiki
Overview
The Proximity Component is a game component that enables entities to spawn enemies when the player enters a certain proximity range. Enemies are initially disabled and only become enabled when the player is within the specified range, triggering a spawn animation.
Properties
- target: The player entity that triggers the proximity detection.
- proximityRange: The range in which the player must be to trigger the spawn animation and enable the entity.
Methods Called
- update(): Checks the distance between the entity and the target player. If within range, triggers the "proximityTriggered" event and enables the entity.
- setupSpawnAnimation(Entity entity): Sets up the spawn animation for the entity. Disables the entity until proximity is triggered, then starts the spawn animation and transitions to the walk animation after completion.
Event Triggers
proximityTriggered: Triggered when the player enters the proximity range. animationEnd: Triggered when an animation completes. Used to transition from the spawn animation to the walk animation.
Example Usage of ProximityComponent:
Entity enemy = new Entity();
ProximityComponent proximityComponent = new ProximityComponent(playerEntity, 10f);
enemy.addComponent(proximityComponent);
proximityComponent.setupSpawnAnimation(enemy);