What’s up with Timmy?

Continued from the previous entry

In the previous entry, we started debugging the issues with the lava puzzle and found a problem with Guybrush colliding with the logs. We also found that a similar problem was occurring with the monkey Timmy, on the beach at Monkey Island. In this post, we’ll try to figure out why Timmy isn’t colliding with Guybrush and just running right through him instead.

Timmy on the Beach, Running Wild!

To begin with, I examined the script that controlled Timmy’s running behavior. When an actor has a monkey that’s running around the actor’s position, a variable named monkey_range is set, which describes the maximum distance that the monkey can run from the actor in each direction. A random value within this range is chosen for the monkey to go to. The monkey runs to this location using the runto method, which is implemented by the Lua command WalkActorTo, which ultimately runs the Actor::walkTo method in ResidualVM. Within this method, the actor checks for collisions while plotting the path.

So, why isn’t Timmy colliding with Guybrush? If we comment the check to print out when actors are checked for collision, we find that we can make Timmy collide with Guybrush if Guybrush walks into him, but not if Timmy runs into Guybrush when Guybrush isn’t moving. If we inspect the logic that makes Timmy move, we find that there’s a method in the Actor class called updateWalk which updates the character’s position over the duration of the walk. If we add some code here to force a collision check when the actor is moving, Timmy stops as expected when he runs into Guybrush.

I suspect that this fixes the lava puzzle collisions too, but currently the logs in the puzzle aren’t showing. I’ll tackle this in the next post! This work is submitted as PR #1050.