logo

Babylon.js Market

By Lawrence

5 minutes

The robot from last lesson stands in the arena. It loops its idle clip and casts a shadow. It looks right, but it does nothing. Walk up to its face and it does not react. Shoot it and it does not flinch. It has a body and an animation, but no senses and no stakes. It cannot tell that you are there. It cannot be brought down. This lesson gives it both. These are the two things that turn a prop into an enemy.

Dark-theme combat event graph: a glowing chain of nodes on near-black — the player ship firing into a bullet, the bullet branching to bullet.hit and health.damage, those converging on health.died, which forks to the enemy's fall animation and a score award — cyan and green neon edges labelled with event names.

Add LineOfSight and Health to the enemy template

You keep the enemy template from last lesson and add two components. LineOfSight lets it see the player. Health lets two bullets bring it down:

// added to the enemy component block from Lesson 5 (the future pool template):
"LineOfSight": { "targetTag": "player", "fov": 220, "range": 32, "rayCount": 3, "blockRadius": 0.6, "interval": 1.5 },
"Health": { "hp": 2, "maxHp": 2 }

LineOfSight brings a new System with it. So it needs the same step from Lesson 5. Add one bare marker stub on World, at the top level. Put it beside the Enemy, Mesh, and SkeletonAnimator stubs that are already there:

// World's marker stubs gain one more:
"LineOfSight": {}

Without the stub, the pooled robots cannot see. The component is on them, but SceneLoader never creates LineOfSightSystem to run the check. Health needs no stub. Its system already came in with the player. The player has carried Health at the top level since Lesson 2.

Continue reading

Unlock the Full Course

Every lesson, the runnable examples, and the finished build — yours to keep.

$9one-time

Was this page helpful?

We read every note — tell us what's working and what isn't.

↑↓ NavigateEnter SelectEsc CloseCtrl+K Open Search