Enemy NPC speed alteration - UQcsse3200/2024-studio-2 GitHub Wiki
Overview
The speed component of Enemy NPC's is altered in the declaration of the enemy in the EnemyFactory.java file. The physical component of the entity is retrieved through a 'get' and then the speed is changed through the "changeMaxSpeed" function. The NPC's speed is specified in the NPCs.json file under each entity with the attribute "speed".
Methods Called
- getComponent(PhysicsMovementComponent.class): Calls the instance of the physics component for the current entity.
- Vector2(config.speed, config.speed): new Vector 2 instance containing the speed of the enemy NPC, has an X and Y component.
- changeMaxSpeed(Vector2()): Alters an entities speed to the specified speed in the inserted Vector.
Event Triggers
- On entity spawn: In enemyFactory, when entity is spawned, methods are called to update the entity instance speed.
Example Usage of update speed:
public class EnemyFactory {
public static Entity createChicken(Entity target) {
BaseEntityConfig config = NPCConfigs.chicken;
chicken.getComponent(PhysicsMovementComponent.class).changeMaxSpeed(new Vector2(config.speed, config.speed));