Hi Tammy,
No worries, I struggled a lot with how to explain it, especially since e-readers constantly renumber pages
The actual agent simulation is working, but in the first half of the chapter (Chapter 13—Planning Routes and Creating Believable AI), if the reader is following along doing the coding, the monsters themselves won’t be participating in the update cycle since the MonsterEntity (that get created by the generators) are not yet in the scene’s entity array. The code that gets the monster to choose to chase the player (changes the goal weight for the interceptGoal
) comes near the end of the section Use Multiple Goals, where the reader adds an update
method to MonsterEntity
.
But, the code to update the adding the monster entities into the scene’s entity array isn’t added until later in the chapter, specifically near the end of the section Update Physics for Monsters and Projectiles. So when the reader first tests picking up the key after adding the chase code, the monsters aren’t going to chase them, because the MonsterEntity
's update
function won’t be triggered yet. I think just relocating the code block that does that to the earlier section would fix it.
if let scene = ocmponentNode.scene as? GameScene {
scene.entities.append(monsterEntity)
}