Build OrbitRun with Smart Shape | Part 6: Battery pickups
Logo

Put a battery where you want your player to fly: near the bottom of a valley. Collecting it adds 8 seconds to the clock. A good dive now buys more time, while the rising pace makes the next valley harder to reach.

Continue from Part 5, or open OrbitRun-18-rising-pace.tap from the checkpoint pack. You can make the battery from the panel graphic and font already in your project.

In the diagrams, REUSE means use the behavior you already added. For a reminder of the gestures, see connecting behaviors in Part 1. You can tap an image to open it at full size.

19. Put the battery in a valley

The course changes on every run, so you need to find a valley before placing a battery. Use Raycast Test to sample the surface at three nearby points. When the middle point is lower than both sides, you’ve found a low spot.

Start with one battery. After the player collects it or flies past, you can move that same object to another valley.

Hold into the valley, collect a battery, then release: actual play from the rebuilt project

Watch the countdown gain eight seconds and the green cell disappear when collected.

Three rays locate a valley, with the battery placed just above its surface

Build the cell

Make a small, bright pickup that stands out against the ground:

A finished battery pickup, sitting just above a valley

  1. Add orbit-panel to the world layer, name it Battery, and resize it into a small badge. Give it a bright tint and place a +8 label named Battery Label over it.
  2. Use centered anchors so the graphic and label line up when moved together. Set Battery to Static, disable its collisions, and hide both objects initially. The placement behaviors will choose their position.
  3. Add batteryActive = 0 to Skimmer’s attributes. Zero means search for a valley; one means keep the current pickup in place.

Search the terrain ahead

See Raycast Test for origins, destinations, layers, and hit outputs. Use the data-output drag demonstrated in Part 2 whenever a field below names another behavior’s result.

Keep these behaviors on Skimmer. Follow the small diagrams in order: search, sample the ground, place the battery, then recycle a miss.

Begin the search chain:

  • Battery Search State (Get Attribute): Skimmer, batteryActive
  • Battery Search Idle (If): Attribute Value equals 0
  • Battery Place Position (Get Position): Skimmer, Screen Coordinates Off
  • Battery Next X (Add Values): Skimmer's X Position + 35
  • Battery Left X (Subtract Values): Battery Next X result − 4

The first guide connects Flight Tick to Battery Search State. The existing 0.05-second timer checks ahead frequently enough to notice a valley even as speed increases. It only casts rays while batteryActive is zero.

Search ahead only when there’s no active battery.

Animated connection guide: Search only while inactive

  1. Reuse Flight Tick.
  2. Add Get Attribute named Battery Search State. Connect a free bottom white circle on Flight Tick to Battery Search State.
  3. Add If named Battery Search Idle. Connect a free bottom white circle on Battery Search State to Battery Search Idle.
  4. Add Get Position named Battery Place Position. Connect Battery Search Idle’s bottom (true) circle to Battery Place Position.
  5. Add Add Values named Battery Next X. Connect a free bottom white circle on Battery Place Position to Battery Next X.
  6. Add Subtract Values named Battery Left X. Connect a free bottom white circle on Battery Next X to Battery Left X.

The next two guides add three Raycast Test behaviors. They all use Closest Object, Any Object, world layer 0, All Layers Off, and destination type Position. Each ray starts at Y 80 and ends at Y −40, so it passes vertically through the course. Use the same X at both ends:

  • Battery Ray Left: Battery Left X result
  • Battery Ray Center: Battery Next X result
  • Battery Ray Right: Battery Right X result, an Add Values calculation of Battery Next X + 4

Battery Ray Left uses Main, the same referenced X at both ends, and Y 80 to −40

After each ray, add an If that checks its Intersected output equals 1. Name the checks Battery Left Hit, Battery Center Hit, and Battery Right Hit. Use each check’s true output to continue. This keeps the search waiting if any ray misses the ground.

Configure the two valley checks in the second sampling guide:

  • Battery Low Left: Center ray's Y Position < Left ray's Y Position.
  • Battery Low Right: Center ray's Y Position < Right ray's Y Position.

Test the left ray before continuing to the center ray.

Animated connection guide: Sample left, then center

  1. Reuse Battery Left X.
  2. Add Raycast Test named Battery Ray Left. Connect a free bottom white circle on Battery Left X to Battery Ray Left.
  3. Add If named Battery Left Hit. Connect a free bottom white circle on Battery Ray Left to Battery Left Hit.
  4. Add Raycast Test named Battery Ray Center. Connect Battery Left Hit’s bottom (true) circle to Battery Ray Center.
  5. Add If named Battery Center Hit. Connect a free bottom white circle on Battery Ray Center to Battery Center Hit.

Aim the ray at the sampled X

Select the receiving behavior, drag the source output into Origin X, choose final value, and check the resulting reference

After you drop it, Origin X contains Battery Next X · final value. Repeat the same drag into Destination X.

After the right ray hits, compare the center height with both sides.

Animated connection guide: Sample right, then find a valley

  1. Reuse Battery Center Hit.
  2. Add Add Values named Battery Right X. Connect Battery Center Hit’s bottom (true) circle to Battery Right X.
  3. Add Raycast Test named Battery Ray Right. Connect a free bottom white circle on Battery Right X to Battery Ray Right.
  4. Add If named Battery Right Hit. Connect a free bottom white circle on Battery Ray Right to Battery Right Hit.
  5. Add If named Battery Low Left. Connect Battery Right Hit’s bottom (true) circle to Battery Low Left.
  6. Add If named Battery Low Right. Connect Battery Low Left’s bottom (true) circle to Battery Low Right.

Place and hold the pickup

The placement guide continues from Battery Low Right’s true output. Use these settings:

  • Battery Ground Y (Add Values): Center ray's Y Position + 1.2
  • Battery Lock (Set Attribute): Skimmer, batteryActive = 1
  • Battery Place (Move to Point): Battery; X = Center ray's X Position; Y = Battery Ground Y result; duration 0, Screen Coordinates Off
  • Battery Label Place (Move to Point): Battery Label; same X and Y, duration 0, Screen Coordinates Off
  • Battery Show (Set Visibility): Battery, Show Graphic
  • Battery Label Show (Set Visibility): Battery Label, Show Graphic

Stop the search, move the battery to the low point, and show it.

Animated connection guide: Lock and place the battery

  1. Reuse Battery Low Right.
  2. Add Add Values named Battery Ground Y. Connect Battery Low Right’s bottom (true) circle to Battery Ground Y.
  3. Add Set Attribute named Battery Lock. Connect a free bottom white circle on Battery Ground Y to Battery Lock.
  4. Add Move To Point named Battery Place. Connect a free bottom white circle on Battery Lock to Battery Place.
  5. Add Move To Point named Battery Label Place. Connect a free bottom white circle on Battery Place to Battery Label Place.
  6. Add Set Visibility named Battery Show. Connect a free bottom white circle on Battery Label Place to Battery Show.
  7. Add Set Visibility named Battery Label Show. Connect a free bottom white circle on Battery Show to Battery Label Show.

Use the surface height

Select the receiving behavior, drag the source output into Y position, choose final value, and check the resulting reference

After you drop it, Y position contains Battery Ground Y · final value. Also use this result in Battery Label Place’s Y field.

The 1.2 m offset keeps the graphic just above the collision surface. The active flag locks its position while the ship approaches, so the cell does not drift with the moving scan.

Recycle a miss

Use the recycling guide below. Configure these properties:

  1. Get Position, alias Battery Position, targeting Battery, Screen Coordinates Off.
  2. Subtract Values, alias Battery Gap: Battery Position's X Position − the existing HUD Position’s X Position output.
  3. If, alias Battery Missed: Battery Gap's result < −6.
  4. Set Attribute, alias Battery Deactivate: Skimmer, batteryActive = 0.
  5. Set Visibility, alias Battery Hide Cell, hiding Battery, followed by Battery Hide Label, hiding Battery Label.

Once the battery is more than 6 m behind the ship, hide it and allow another search.

Animated connection guide: Recycle a missed battery

  1. Reuse Position.
  2. Add Get Position named Battery Position. Connect a free bottom white circle on Position to Battery Position.
  3. Add Subtract Values named Battery Gap. Connect a free bottom white circle on Battery Position to Battery Gap.
  4. Add If named Battery Missed. Connect a free bottom white circle on Battery Gap to Battery Missed.
  5. Add Set Attribute named Battery Deactivate. Connect Battery Missed’s bottom (true) circle to Battery Deactivate.
  6. Add Set Visibility named Battery Hide Cell. Connect a free bottom white circle on Battery Deactivate to Battery Hide Cell.
  7. Add Set Visibility named Battery Hide Label. Connect a free bottom white circle on Battery Hide Cell to Battery Hide Label.

Follow a cell toward a valley. It should stay attached to that spot in the course. Fly over it and watch it disappear after passing behind the ship; a later valley can receive the next cell. Collection is added in step 20.

The pickup uses world coordinates, so it stays on the course as the camera zooms. Once batteryActive is 1, the search stops and leaves that battery in place.

You can adjust how far ahead the search looks (35 m) or how far apart it samples (4 m). Change one setting and watch where the next battery appears. If you change the course’s height or position, keep every ray’s start above the hills and its end below the valleys.

20. Collect energy, then end the run when it is empty

The earlier prototype had a fixed Run Limit timer. That timer must go: otherwise the game would finish at 90 seconds even after collecting batteries.

Detect a collection

Check for a collection only while a battery is active. If the ship is close enough, add the bonus and hide the battery before the next check.

Use these settings:

  • Battery Collect State: Skimmer, attribute batteryActive.
  • Battery Collect Active: Attribute Value Equals 1.
  • Battery Distance: Calculate Distance; Object A = Skimmer, Object B = Battery, Compensate for Zoom On.
  • Battery Near: Battery Distance’s Value < 2.5.
  • Battery Bonus: its own result + 8, initial result 0.
  • Battery Capacity: first number 90, second number from Battery Bonus’s result.

An active battery can be collected when the ship is less than 2.5 m away.

Animated connection guide: Check active, then distance

  1. Reuse Flight Tick.
  2. Add Get Attribute named Battery Collect State. Connect a free bottom white circle on Flight Tick to Battery Collect State.
  3. Add If named Battery Collect Active. Connect a free bottom white circle on Battery Collect State to Battery Collect Active.
  4. Add Calculate Distance named Battery Distance. Connect Battery Collect Active’s bottom (true) circle to Battery Distance.
  5. Add If named Battery Near. Connect a free bottom white circle on Battery Distance to Battery Near.
  6. Add Add Values named Battery Bonus. Connect Battery Near’s bottom (true) circle to Battery Bonus.

Add the earned seconds to capacity and deactivate the collected battery.

Animated connection guide: Add energy and retire the cell

  1. Reuse Generate.
  2. Reuse Battery Bonus.
  3. Add Add Values named Battery Capacity. Connect a free bottom white circle on Generate to Battery Capacity. Connect a free bottom white circle on Battery Bonus to Battery Capacity.
  4. Reuse Battery Deactivate. Connect a free bottom white circle on Battery Bonus to Battery Deactivate.
  5. Reuse Remaining. Connect a free bottom white circle on Battery Capacity to Remaining.

Battery Bonus holds all earned seconds. Battery Capacity holds starting energy plus earned energy. The existing Seconds behavior continues counting elapsed time.

Update the countdown and finish condition

The Timer reference helps distinguish the repeating display update from the one-shot run limit you’re replacing.

  1. In Remaining, replace the constant A value 90 with Battery Capacity’s result output. Leave B connected to Seconds’ result output.
  2. Keep the two connections made in the energy guide: Battery Capacity to Remaining, and Battery Bonus to Battery Deactivate. The pickup is hidden and marked inactive immediately after one award, preventing repeated collection. The search can then place it in another valley.
  3. Delete the old Run Limit timer and its connections.
  4. In the finish guide below, set Energy Empty to compare Remaining’s result ≤ 0. Reuse Finished and keep Remaining’s existing Clock Text connection.
  5. Battery Hide End hides Battery; Battery Label Hide End hides Battery Label. Both use Set Visibility. Connect them using the finish guide below.

Use energy capacity in the clock

Select the receiving behavior, drag the source output into First number (A), choose final value, and check the resulting reference

After you drop it, First number (A) contains Battery Capacity · final value. Keep the second number referencing Seconds.

Let Remaining trigger Finished when the energy reaches zero.

Animated connection guide: Finish when energy is empty

  1. Reuse Remaining.
  2. Reuse Clock Text and keep its existing connection from Remaining.
  3. Add If named Energy Empty. Connect a free bottom white circle on Remaining to Energy Empty.
  4. Reuse Finished. Connect Energy Empty’s bottom (true) circle to Finished.
  5. Add Set Visibility named Battery Hide End. Connect a free bottom white circle on Finished to Battery Hide End.
  6. Add Set Visibility named Battery Label Hide End. Connect a free bottom white circle on Battery Hide End to Battery Label Hide End.

The energy relationship is now:

remaining seconds = 90 + earned battery seconds − elapsed seconds

Energy and difficulty use separate counters

Reuse your Finished group. It already stops the timers and ship, shows the result, and checks the best score.

Make collection satisfying and clear

  1. The collection-reward guide adds Battery Chime (Play Sound). Use the same settings and chime asset as Flow Sound.
  2. Battery Message (Change Label) targets Flow Label, with text +8s BATTERY.
  3. Follow the two branches in the collection-reward guide below.
  4. Set Battery Hide to 1.3 seconds, once, Start Immediately Off. Reuse Show Flow and Hide Flow as shown.
  5. Disconnect Velocity → Flow Check. This reserves the feedback label for battery messages, so a speed message does not overwrite a collection message. The trail and other effects remain active.
  6. Change the title instructions to Hold downhill. Release at the valley. Valley batteries add 8 seconds of flight. Change the result title's starting text to BATTERY EMPTY. The personal-best branch may replace it with NEW PERSONAL BEST.

Play the chime and show how much time the player gained.

Animated connection guide: Show the collection reward

  1. Reuse Battery Bonus.
  2. Add Play Sound named Battery Chime. Connect a free bottom white circle on Battery Bonus to Battery Chime.
  3. Add Change Label named Battery Message. Connect a free bottom white circle on Battery Bonus to Battery Message.
  4. Reuse Show Flow. Connect a free bottom white circle on Battery Message to Show Flow.
  5. Add Timer named Battery Hide. Connect a free bottom white circle on Battery Message to Battery Hide.
  6. Reuse Hide Flow. Connect a free bottom white circle on Battery Hide to Hide Flow.

The completed rebuild explains the battery mechanic on its title screen

Watch the clock as you collect a cell. It should gain eight seconds, show the collection message, and remove that cell once. A new valley can then receive a battery. Keep flying beyond the original 90-second point after earning extra energy. On a later run, miss the cells and let energy reach zero; the normal results and replay flow should still work.

A battery adds time to Battery Capacity. Seconds keeps counting upward, so the pace from Part 5 keeps rising too. That gives you a reason to chase the next battery and a harder flight when you reach it.

Debug by symptom

  • The cell adds seconds continuously: Battery Bonus must trigger Battery Deactivate; collection must be gated by batteryActive = 1
  • The pickup only works at one zoom level: Calculate Distance must have Compensate for Zoom On
  • It ends at exactly 90 seconds after a pickup: Remove the old Run Limit timer; Energy Empty should trigger Finished
  • The clock jumps to a negative value immediately: Generate must run Battery Capacity to initialize 90 seconds; Battery Bonus and Seconds start at 0
  • The label moves but the green cell stays behind: Battery Place must target Battery; Battery Label Place must target Battery Label
  • The ship cannot reach batteries: Check the three ray hit conditions, the two low-point comparisons, and the 1.2-meter surface offset

Your next experiment

Play a few runs before adding anything else. Can you spot a battery soon enough to aim for it? Does collecting one give you enough time to reach another? Those answers are more useful now than another feature.

When you’re ready to extend the project, try a short row of batteries leading down into a valley. You’ll need a small pool of objects, with each battery awarding its bonus once. Use their placement to guide the player toward a good release.