Skip to content

Tutorials · Navigation and AI · Chapter 1

Rounds

20 minutes Uses: Path, PathFollow

By the end

  • hall_round, a closed Path of four points round the great hall, and the hall guard walking it at 40 a second from its second corner
  • corridor_round, an open Path end to end of the corridor, and the corridor guard under it, walking it there and back
  • hearth_loop, a closed, smooth loop round the hearth, and the cat under it walking it the other way round
  • Every field of the Path and of the Path Follow, and which of them moves each node
On this page

The keep you start from

Navigation and AI does not start from an empty folder. It starts from a keep at night, built and seen from above, with a thief who walks and nothing else that moves. Everything you add from here is something that finds its way.

  1. Download navigation-and-ai.zip, the starter (the overview says what is in it), and unzip it somewhere outside your other projects. You get one folder, navigation-and-ai.
  2. Open Rengy. In the launcher, choose Open project… and pick the navigation-and-ai folder.
  3. The editor opens the project’s startup scene, scenes/keep.ron. In the Hierarchy, select keep, move the pointer over the Viewport and press F to frame it.
  4. Press F5. Walk the thief with W, A, S and D, or the arrow keys. Press F5 again to stop.
The editor on the starter with keep selected: the Hierarchy lists keep and its nodes, room, floor, hearth, bell, the three tables, key, pots, bowl, the two doors, carpet, mud, hole, ladder, hatch, the thief with her camera, the two guards and the cat; the Viewport shows the whole keep from above: the great hall with its hearth, bell, two tables, a guard and the cat at the top left, the kitchen and the store room beside it, the carpeted corridor with its ladder across the middle, and the cellar, the gallery and the muddy courtyard at the bottom, where the thief stands by the gate
The game a second after it starts: the thief standing at the courtyard’s east end, where the starter puts her, the strip of mud to her left, and above her the carpeted corridor and the store room’s door in its wall

The keep is 40 tiles across and 22 down, each tile 16 world units: 640 by 352. Across the top are the great hall, with the hearth, the bell and two tables, then the kitchen, then the store room, with a table, the key and a hole in its floor. Under them runs the corridor, carpeted along its lower row, with a ladder down. Under that are the cellar, the gallery and the courtyard, which is mostly mud, and whose gate is where the thief starts.

The camera is the thief’s child, so the view follows her. It shows 320 by 180 world units, drawn four times their size in a 1280 by 720 window, and a Confiner holds it inside the keep. Every position on these pages is in world units, with 0, 0 at the keep’s top left and y growing downward.

The thief walks at 70 a second, and the walls stop her. The two guards stand at their posts, guard_hall in the hall and guard_corridor at the corridor’s west end, and the cat sits by the hearth. None of them moves yet: this chapter walks them round their rounds.

The art folder holds the keep’s tiles and the pictures drawn for it. Some are for later chapters and came with the starter: the guard’s cone of sight and his three poses, the lever, the cart, the sheep and the turret. Each chapter that uses one says so.

A round for the hall guard

A guard’s round is a Path: a line of points the editor draws over the room, which something can walk. A Path is a component, and a Path node is a node that has one. The hall guard’s round is a rectangle inside the hall, round the two tables.

  1. Select keep, press + Add node, and choose Path. Rename it hall_round. Leave its Position at 0, 0, so its points are where they are in the keep.
  2. In the Inspector, press the + beside Points four times. Type each point’s x and y: click a box once, type the number and press Enter. The points are 56, 72, then 264, 72, then 264, 168, then 56, 168.
  3. Tick Closed.

With hall_round selected, every point is a small square in the Viewport, and the line runs through them in order. You can draw the points there instead of typing them.

hall_round selected and framed: a rectangle of thin violet lines over the great hall with a small square at each of its four corners, the two tables inside it and the hall guard standing on its top left corner, the hearth loop’s curve cut off at the top; the Inspector shows its Path with four Points, 56 and 72, 264 and 72, 264 and 168, 56 and 168, Closed ticked and Smooth unticked
Points
The Path’s points, in order, in its node’s own space: a Path at 0, 0 has them where they are in the keep, and moving the node moves them all. A walker goes from each point to the next in a straight line. Two points are enough for a line; the hall round has four, its corners 208 and 96 apart.
Closed
Whether the Path’s last point joins its first, so the line goes round. Ticked, the hall round is a loop of 608 units and a walker on it never reaches an end. Unticked, the line stops at its last point.
Drawing points in the Viewport
With the Path selected, drag a point’s square to move the point. Double-click a line to put a new point on it, and hover a point’s square and press Backspace to take the point away. The arrows beside each point in the Inspector move it earlier or later in the list.

The hall guard follows it

A Path moves nothing. A Path Follow on a node walks that node along a Path, at its own speed, from its own place on it. The hall guard gets one, and names his round.

  1. Select guard_hall, press Add component and choose PathFollowComponent.
  2. Click Path’s box: a list of the scene’s paths opens. Click hall_round in it (typing hall narrows the list).
  3. Set Progress to 208 and Speed to 40. Leave Rotate unticked, Playing ticked and At End on Stop.
  4. Press Ctrl+S.
  5. Press F5. The hall guard stands on the round’s second corner, top right, and walks down its east side, then west, up and east again, round and round.
  6. In Play, select guard_hall and untick Playing: he stops where he is. Tick it again and he walks on from there. Press F5 to stop.
guard_hall selected, the hall round framed in the Viewport with the guard on its top left corner and his move arrows on him; the Inspector, narrowed by its search box to follow, shows his PathFollowComponent: Path hall_round, Progress 208.00, Speed 40.00, Rotate unticked, Offset 0.0 and 0.0, Playing ticked, At End Stop
Path
The Path Follow’s Path: the name of the node whose Path it walks. A name finds that node anywhere in the scene; empty, it shows (none) and walks its own parent’s Path, as the corridor guard’s will. The path is walked in the follower’s parent’s space: the hall guard’s parent is keep, at 0, 0, so he walks the round where it is drawn.
Progress
The Path Follow’s place along the path, in world units from its first point. Play starts it there: 208 is the length of the hall round’s first side, so the hall guard starts on its second corner, 264, 72. Once round the hall is 608.
Speed
How fast the Path Follow walks, in world units a second along the path. 40 walks the hall round’s east side, 96 long, in 2.4 seconds; 30 to 60 suits a guard here, slower than the thief’s 70. A negative Speed walks the path backwards, which the cat below does.
Rotate
Whether the Path Follow turns its node to face along the path. Unticked, the node keeps its own turn. Every walker in the keep leaves it off: the guards and the cat are drawn upright, and the cat, drawn from the side, would hang upside down on the far side of its loop. The gallery’s cart, seen from above, turns with its track in chapter 13.
Playing
Whether the Path Follow walks. Unticked, it stands where its Progress says, and ticked again it walks on from there. Saved ticked, it walks from the start of Play.
At End
What the Path Follow does at the end of an open path: Stop stands there and unticks Playing, and PingPong turns round and walks back. A closed path has no end, so the hall round’s Stop never comes into it.

A parent’s path

The corridor guard walks the corridor end to end and back. His round is an open Path, and he goes under it in the Hierarchy, so his Path Follow needs no name: empty, it walks its parent’s.

  1. Select keep, press + Add node, choose Path and rename it corridor_round. Leave its Position at 0, 0.
  2. Press the + beside Points twice and type 40, 232, then 600, 232. Leave Closed unticked.
  3. In the Hierarchy, drag guard_corridor onto corridor_round. He stays where he stood: his new parent is at 0, 0, so his own Position, 40, 232, is the same place.
  4. Select guard_corridor, press Add component and choose PathFollowComponent. Leave Path as it is, (none). Set Speed to 48, and choose PingPong in At End.
  5. Press Ctrl+S, and press F5. He walks east along the corridor, above the carpet, reaches the far end after about 11.7 seconds, and walks back. Press F5 to stop.
guard_corridor selected under corridor_round in the Hierarchy; the Viewport, framed on the carpet, shows the keep from the hall’s tables down, with the guard at the corridor’s west end and a thin line running from him east along the corridor’s upper row, above the carpet; the Inspector, narrowed to follow, shows his PathFollowComponent: Path (none), Progress 0.00, Speed 48.00, Rotate unticked, Offset 0.0 and 0.0, Playing ticked, At End PingPong
Five pictures of the corridor’s east end side by side: the corridor guard against the wall’s face above the carpet walks right towards the east wall over the first three, stands closest to it in the third, and walks back left over the last two
Steps 660, 680, 700, 720 and 740 of Play, 11 to 12.33 seconds: at step 700 he is at the far end, 600, 232, and he turns there.

At each end PingPong turns him by flipping his Speed: 48 going east, -48 coming back. Nothing in the keep tells a Path Follow which way it is going but the sign of its Speed, which is also how the cat goes round its loop backwards below.

The cat’s loop

The cat walks a small loop in front of the hearth, round its own spot. The loop is a Path of its own, moved to the hearth, with its points round its middle and its corners rounded off.

  1. Select keep, press + Add node, choose Path and rename it hearth_loop. Set its Position to 144, 52, the cat’s spot.
  2. Press the + beside Points six times and type -24, 0, then -12, 14, then 12, 14, then 24, 0, then 12, -10, then -12, -10. Tick Closed and Smooth.
  3. In the Hierarchy, drag cat onto hearth_loop. Set the cat’s Position to 0, 0, its parent’s middle: the same spot as before.
  4. With cat selected, press Add component and choose PathFollowComponent. Leave Path as (none), its parent’s. Set Speed to -20 and Offset to 0, -3. Leave Rotate unticked.
  5. Press Ctrl+S.
hearth_loop selected, seen through the game camera with the thief standing beside the hearth: a smooth, closed violet loop round the side-on cat under the hearth, with six small squares on it, the hall round’s rectangle faint below; the Inspector shows its Position 144.0 and 52.0 and its Path with six Points, -24 and 0, -12 and 14, 12 and 14, 24 and 0, 12 and -10, -12 and -10, Closed and Smooth both ticked
Seen through the game camera, with the thief placed by the hearth for the picture.
Smooth
Whether the Path’s corners are rounded into a curve. Ticked, the line bends through every point instead of turning sharp at it, so six points make the oval round the hearth. A walker follows the curve. Unticked, the line is straight from point to point, as the guards’ rounds are.
Offset
How far the Path Follow stands its node off the path, in world units, x then y. The cat’s node is the middle of its picture, so with no offset the curve would run through its middle; 0, -3 lifts it 3 units, y growing downward, and the curve runs low across its legs, where a walking cat meets the floor. The offset turns with the path only when Rotate is ticked.
A negative Speed
The Path Follow’s Speed below 0 walks the path from its end towards its start. The loop’s points go round the hearth left, down, right and up, so the cat at -20 goes left, up, right and down, a slow walk the other way round.

The rounds

The three paths, each a Path node under keep:

NodeParentPositionPointsClosedSmooth
hall_roundkeep0, 056, 72; 264, 72; 264, 168; 56, 168tickedunticked
corridor_roundkeep0, 040, 232; 600, 232untickedunticked
hearth_loopkeep144, 52-24, 0; -12, 14; 12, 14; 24, 0; 12, -10; -12, -10tickedticked

The three followers, each a Path Follow on a node the starter has. Every other field is as a new Path Follow has it: Rotate unticked, Playing ticked, At End on Stop.

NodeParentPathProgressSpeedOffsetAt End
guard_hallkeephall_round208400, 0Stop
guard_corridorcorridor_round(none)0480, 0PingPong
cathearth_loop, at 0, 0(none)0-200, -3Stop

Check it works