Small Issue in Part 6
Mozahler opened this issue Β· comments
Mozahler commented
I'm absolutely loving this series! Thanks so much. ππ»
I stumbled through this part of the update [line 495], and just wanted to let you know.
Now, in the Monster.update()
method, modify the state machine again to swap the animations:
switch monster.state {
case .idle:
if monster.canSeePlayer(in: self) {
state = .chasing
animation = .monsterWalk
}
case .chasing:
guard monster.canSeePlayer(in: self) else {
state = .idle
animation = .monsterIdle
break
}
...
}
I changed it so it would compile (leaving the velocity intact for now) :
mutating func update(in world: World) {
switch state {
/// all the monster needs to do is wait until it sees the player.
/// That means we need a method to detect if the monster can see the player
/// since they always face the player, just check if there is a wall between them
case .idle:
if canSeePlayer(in: world) {
state = .chasing
animation = .monsterWalk
}
velocity = Vector(x: 0, y: 0)
case .chasing:
guard canSeePlayer(in: world) else {
state = .idle
animation = .monsterIdle
break
}
let direction = world.player.position - position
velocity = direction * (speed / direction.length)
}
}
Nick Lockwood commented
@Mozahler fixed. Thanks for flagging it π