Slow Rush Studios logo,
    depicting an apprehensive-looking snail rushing forward

Slow Rush Studios

◂  Target Practice
News index
Hot Pursuit  ▸

Pew Pew Pew

Contents

This week, enemies learned to see the player and shoot in their general direction, which increased their deadliness by approximately infinity percent.

Perceiving Players

The easy way to check whether a player is visible to enemies is via "ray casting": you start at an enemy and you draw a line to where a player is; if you get to the player without hitting anything along the way, the player is visible to that enemy!

Fortunately the physics engine I'm using has ray-casting built in, so that generated colliders will block rays. Perfect!

Raycasting using Rapier. It works fine for moving bodies, but atoms sometimes don't block vision.
(Just ignore that the enemy is facing the wrong way!)

Unfortunately, I forgot that I applied an optimization: we only generate colliders for atoms close to the player and to enemies.

You can see it more clearly with some debug output on:

Only the 64x64 pixel squares with thick green borders are getting colliders created.

So I swapped to my own custom raycasting, which simply looks at atoms one by one along the path of the line. 1

Now atoms always block line of sight.

This variant does have the opposite problem of being able to (always) see through moving bodies, but I think that will be okay gameplay-wise.

Enemy AI

These days, AI is a blanket term for magic sauce that causes people to throw money at your company.

But it wasn't that long ago that the only (non-academic) people seriously interested in AI were game developers.

Yet game AI is less making game entities intelligent and more making them fun (or challenging, or frustrating, or ...). Design the experience, then fake as much as you can.

So, I want enemies to start unaware of the player, and attack the player once they've spotted 'em:

A state machine showing transitions between idle and attack based on visibility
Sketch of our desired behavior so far

Actually, probably enemies should attack more than just the once, so we'll need a timer to track when they can attack next.

I also want the player to have the satisfaction of running up and using a close-ranged spell if they're fast enough, so enemies should have a brief period of surprise-driven inaction when they first spot the player.

But if the player hides then enemies shouldn't be surprised again if the player pops up immediately; enemies should remember they saw the player recently.

An updated state machine showing surprised and search states which are exited/entered based on timers elapsing
Our new desired behavior. (Enemies start in the Idle state.)

This is what nerds2 call a State Machine.

And here's what it looks like in action:

Enemy AI in action, with debug visualization (explained below).

Obviously the enemy would be rather more effective in searching for the player if they were to, you know, move around a bit - but that's a whole 'nother topic.

(And yes, in this magical world, arrows travel in a straight line unaffected by gravity.)

The First Playtest

Sure, there are online demos here, but this week I attended a couch co-op session, so I had 2-3 peeps play my demo without reading any of my copious words beforehand.

And wow! This first playtest was both impressively embarrassing3 and wonderfully eye opening:

Thank you to those poor souls. (Also please stop abusing the laser in Bopl Battle!)

Arrow-filled web build‎

Dodge some goblin arrows here:

Click to focus, then play with keyboard and mouse. No mobile support! Give feedback.

For the enemy vision visualization, press F2 and turn on Enemies >> Show vision.

And yeah, the enemies don't have attack animations yet - all in due course.


1

The actual algorithm for stepping pixel-by-pixel is an integer-arithmetic only version of Bresenham's line algorithm. Conveniently I already had it floating around because it's used for some of the water movement logic, and for painting atoms using the paint tool without any gaps when you move the mouse really quickly.

2

proudly including me.

3

Other game devs have mentioned that the first play test is always embarrassing, but you don't get it until you're in the hot seat.

◂  Target Practice
News index
Hot Pursuit  ▸