Enemy NPC Combat Initiation - UQcsse3200/2024-studio-2 GitHub Wiki

Overview

The TouchAttackComponent is a component that enables an entity to attack other entities on collision, without knockback. It listens for collision events and checks if the collided entity matches the target layer. If a match is found, it triggers a combat event.

Properties

targetLayer: The physics layer of the target's collider.

Methods Called

create(): Sets up the component and adds a listener for the "collisionStart" event.

onCollisionStart(Fixture me, Fixture other): Handles the "collisionStart" event and checks if the collided entity matches the target layer. If a match is found, triggers a combat event.

Event Triggers

startCombat: Triggered when the entity attacks another entity.

Example Usage of TouchAttackComponent

Entity enemyNPC = new Entity();
TouchAttackComponent touchAttackComponent = new TouchAttackComponent(targetLayer);
enemyNPC.addComponent(touchAttackComponent); ```