-
Notifications
You must be signed in to change notification settings - Fork 1
Enemy NPC Player Detection
LJ edited this page Aug 28, 2024
·
5 revisions
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.
- 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.
- 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.
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.
Entity enemy = new Entity();
ProximityComponent proximityComponent = new ProximityComponent(playerEntity, 10f);
enemy.addComponent(proximityComponent);
proximityComponent.setupSpawnAnimation(enemy);