Skip to content
Bit Quirky Round Trip
Visual Scripting

Search documentation

All topics and APIs

Close returns focus to Search.

What are you looking for?

Try a common topic or a C# feature.

Browse the reference instead

Esc closes · Tab reaches results · Enter opens the focused link

v1.0.0
Menu

Turn at the edge

Build a branch and an else-if branch on the canvas that turn a patrol around only when it is moving past an edge.

Reaching an edge is only half the reason to turn. This shape turns a patrol around when it is at an edge and still moving toward it, so it never flips back and forth while it rests on the line. On the canvas it is two yellow BRANCH nodes in a chain: the second one hangs off the first one’s false output, so it only asks its question when the first answer was no. In the Platformer sample, each enemy patrol checks its position and its direction before it turns around.

This page builds that shape from an empty canvas. It uses the sample’s EnemyPatrol class so every name on the nodes is real. In your own project, build the same shape in any class that reverses at a limit, once its folder is indexed.

A patrol walks between a left X position and a right X position. At the left edge it should face right, but only if it was walking left. At the right edge it should face left, but only if it was walking right. Every other physics step keeps the current direction.

  • A patrolling enemy, a moving platform, or a sliding camera travels between two limits and turns back at each one.
  • A value bounces between a low and a high mark, such as a pulsing light or a swinging door.
  • Two checks can never both be true, and the second should only run when the first one fails.

Build the two-edge turn

  1. Create TurnAtEdge

    Open Tools > Round Trip > Graph view, press Cmd/Ctrl+O and choose EnemyPatrol. Press the + on the Methods section of the left rail, type TurnAtEdge in the name box and press Enter. The canvas shows a magenta entry node titled TurnAtEdge with an Exec pin.

    Clip: Ctrl+O opens the class picker, EnemyPatrol is chosen, + on Methods adds a method, TurnAtEdge is typed and Enter creates it. A magenta TurnAtEdge entry node lands alone on the canvas with an Exec pin.
    The whole Graph view with EnemyPatrol open and no method on the Methods rail yet, with the plus beside Methods on the left rail highlighted and an arrow pointing at it.
  2. Read the position

    Read the position once. Right-click blank canvas, type _rigidbody, and press get. Drag from the purple pill onto empty canvas and press get on position. Drag from the new pill and press get on x. You now have a pill for the patrol’s X position.

    Clip: the pointer right-clicks blank canvas, types _rigidbody and presses get. A purple pill is dragged onto empty canvas and get is pressed on position, then a pill from that gets x. While the pointer rests on a pill to drag from, it is highlighted with an arrow pointing at it. Each menu choice is highlighted with an arrow pointing at it while the pointer rests on it: the get button on the position row, then the get button on the x row.
  3. Place the first branch

    Place the first branch. Right-click and pick branch under flow control. Wire the entry node’s Exec into it.

    Clip: the pointer right-clicks blank canvas and picks branch under flow control. A yellow BRANCH node lands and a white wire runs from the entry node Exec pin into it. While the pointer rests on the entry node's Exec pin to drag from, it is highlighted with an arrow pointing at it. The menu choice is highlighted with an arrow pointing at it while the pointer rests on it: the branch row.
  4. Build the left-edge test

    Build the left-edge test. From operators, place Less or equal: wire the x pill into Left and a _leftBoundX pill into Right. Place Less than: wire a _direction pill into Left and type 0 into Right. Place And and wire both red Result outputs into its Left and Right. Wire the And node’s Result into the branch’s Condition.

    Clip: Less or equal is placed from the operators menu, an x pill is dragged into its Left and a _leftBoundX pill into its Right. While the pointer rests on a pill to drag from, it is highlighted with an arrow pointing at it. The menu choice is highlighted with an arrow pointing at it while the pointer rests on it: the Less or equal row.
    Clip: Less than is placed with a _direction pill on its Left and 0 typed on its Right, an And node is placed, both red Result outputs are wired into it and its Result into the branch Condition. While the pointer rests on a pill or pin to drag from, it is highlighted with an arrow pointing at it. Each menu choice is highlighted with an arrow pointing at it while the pointer rests on it: the Less than row, then the And row.
  5. Turn right

    Turn right. Right-click, type _direction and press set. A navy SET node with a _direction pin appears. Click that pin and type 1. Wire the branch’s true output into it.

    Clip: a navy _direction SET node is placed from the canvas menu, 1 is typed into its value, and the branch true output is wired into its Exec. While the pointer rests on the branch's true output to drag from, it is highlighted with an arrow pointing at it.
  6. Add the else-if

    Add the else-if. Right-click the branch node and choose Edit branch arms. The Branch arms panel lists the arm you have, numbered, with Wired shown where its condition comes from a wire. Press Add else if. A second yellow BRANCH node appears below the first, already joined to its false output by a white wire. Click outside the panel to close it.

    Clip: the Branch arms panel lists the arm, Add else if is pressed, and a second yellow BRANCH node appears below the first, joined to its false output by a white wire. A click outside the panel closes it.
  7. Build the right-edge test

    Build the right-edge test the same way. Place Greater or equal with the x pill on Left and a _rightBoundX pill on Right, place Greater than with a _direction pill on Left and 0 typed on Right, join them on an And node, and wire its Result into the second branch’s Condition.

    Clip: Greater or equal is placed, an x pill is dragged into its Left and a _rightBoundX pill into its Right. While the pointer rests on a pill to drag from, it is highlighted with an arrow pointing at it. Each menu choice is highlighted with an arrow pointing at it while the pointer rests on it: the get button on the x row, then the Greater or equal row.
    Clip: Greater than is placed with a _direction pill on its Left and 0 typed on its Right, a second And node is placed, both red Result outputs are wired into it and its Result into the second branch Condition. While the pointer rests on a pill or pin to drag from, it is highlighted with an arrow pointing at it. Each menu choice is highlighted with an arrow pointing at it while the pointer rests on it: the Greater than row, then the And row.
  8. Turn left

    Turn left. Place another SET node for _direction, type -1 into its _direction pin, and wire the second branch’s true output into it.

    Clip: a second navy _direction SET node is placed, -1 is typed into its value, and the second branch true output is wired into its Exec. While the pointer rests on the branch's true output to drag from, it is highlighted with an arrow pointing at it.
  9. Meet at the next node

    If work should run every physics step after the decision (the sample sets the patrol’s speed there), place that node and wire three white wires into its Exec: from each SET node’s Exec output and from the second branch’s false output. All three routes meet there.

    Clip: a purple wire is dragged from the _rigidbody pill onto empty canvas and WakeUp is chosen. Three white wires then run into its Exec: from each SET node Exec output and from the second branch false output. While the pointer rests on a pill or pin to drag from, it is highlighted with an arrow pointing at it. The menu choice is highlighted with an arrow pointing at it while the pointer rests on it: the WakeUp row.
  10. Compile

    Press Compile in the toolbar.

    The reloaded TurnAtEdge canvas after Compile, whole window with the right rail open: the left-edge test and the right-edge test feed two yellow BRANCH nodes chained on false, each true output runs to a navy _direction SET node holding 1 or -1, and three white wires meet at a teal WakeUp node. Each _direction pill carries a small yellow comment marker. The toolbar Compile button is highlighted with an arrow pointing at it.
    The whole Graph view of EnemyPatrol with the finished TurnAtEdge canvas before Compile, with the toolbar Compile button highlighted and an arrow pointing at it. Compile is amber because the canvas holds changes that are not in the C# file yet.

If you also work in C#, this is the sample’s FixedUpdate, drawn as the diagram beside the code. Your TurnAtEdge writes the same if and else if pair.

Work wired after the meeting point runs on every step. Work placed on only one true route would skip the other turn and every ordinary step.

When it goes wrong

SymptomCheckFix
The enemy jitters at an edge.Look at each branch's And node: does it take a _direction comparison as well as a position comparison?Add the Less than or Greater than node on _direction and wire it into that And node.
Both edge checks run on the same step.Follow the white wire into the second BRANCH node.It should come from the first branch's false output. Use Edit branch arms and add else if to rebuild the chain.
The patrol stops falling or jumping.Look at the velocity nodes after the meeting point: do they replace the whole velocity?Read the current velocity into a local, set only its x, then set it back on the rigidbody, as the sample does.
Full-size image