Repository navigation
Traveler NPC
Adi edited this page Sep 14, 2026
·
2 revisions
public static Entity createTravelerNPC() {
final float floorCollisionScale = 0.05f;
final float playerHeight = 1000f / 792f;
AITaskComponent aiComponent =
new AITaskComponent()
.addTask(new PlatformWanderTask(new Vector2(0.5f, 0.5f), 2f, floorCollisionScale));
Entity npc =
new Entity()
.addComponent(new PhysicsComponent())
.addComponent(new PhysicsMovementComponent())
.addComponent(new ColliderComponent())
.addComponent(new HitboxComponent().setLayer(PhysicsLayer.NPC))
.addComponent(aiComponent)
.addComponent(new CombatStatsComponent(50, 0))
.addComponent(new TextureRenderComponent("images/enemies/npc_traveler.png"));
npc.getComponent(TextureRenderComponent.class).scaleEntity();
npc.scaleHeight(playerHeight);
PhysicsUtils.setScaledCollider(npc, 0.9f, 0.7f);
return npc;
}
It is used to create a passive NPC that wanders around but can't attack. PhysicsComponent and ColliderComponent make it solid, so the player collides with it instead of walking through it. CombatStatsComponent(50, 0) gives it health but no attack, so it can be hit but never hurts the player.
private void spawnTravelerNPC() {
Entity travelerNPC = NPCFactory.createTravelerNPC();
spawnEntityAt(travelerNPC, TRAVELER_NPC_SPAWN, true, true);
}
It is used to actually place the NPC into the level. It calls createTravelerNPC() to build the NPC, then spawnEntityAt() places it at a fixed position, so it's always in the same spot.
private static final GridPoint2 TRAVELER_NPC_SPAWN = new GridPoint2(4, 13);
This is where the NPC spawns.
"images/enemies/npc_traveler.png",
Added an image for NPC