Automated Natural Wall-Offs With Ray Casting Choke Detection

In this episode, @david (creator of Arty Bot) walks through the ray casting system that powers his automated natural wall-off

What’s Covered

  • Choke point detection via ray casting — Casting outward from the natural, stepping through angles to find the two closest choke corners across flat ground, narrow ramps, and wide ramps
  • Map sweeps & corner collection — Two separate directional sweeps to locate the tightest points, then stepping inward to snap placements to the half-integer grid
  • Pylon placement optimization — Using Pythagorean theorem to find the furthest pylon position that still powers all buildings, maximizing space between pylon and gateways
  • Sealed vs gap wall-offs — Tradeoffs between a fully sealed wall and a one-tile gap (between gateway and cyber core), and the extra logic gap walls require

Key Concepts

Concept Detail
Ray casting from natural ~100 degree arc, 40 degree step-out
Map sweeps Two directional sweeps per choke
Pylon optimization Pythagorean theorem for max-distance power coverage
Wall-off types Sealed wall vs one-tile gap
Grid snapping Half-integer grid for building placement

Testing on previous season ladder maps, I thought golden aura had an issue but it did work however, it did have a problem finding the exact corner points so the 3x3 buildings on one side were a bit far out making them have more surface area when being attacked by lings.

On a map like site delta we also have the issue of stepping out too far when using 7 distance, so maybe 6 would be better on that map as well, otherwise it is causing an issue with finding the corner points and maybe the ramp itself, I will have to dig more into that because it’s actually failing to correctly find the gateway locations.

I do believe there is a single raycasting formula that can be used for every map correctly. Apologies for my sub optimal explanation.

Additional info:
from our natural, point towards map center using a100 degrees radial sweep so -50 to 50 degrees facing the map center from natural with 2 degrees between each raycast, with increments of 1 degree steps along the line of the raycast.

From that I step in by 7 and from there I use a 90 degree left and 90 degree right sweep (total 180 degree sweep split into 2 separate sweeps) of our ramp direction with a 1 degree between each raycast and incrementing by 0.5 along those raycast lines, each sweep will calculate its closest point to our starting point, from there we need to snap to half integer to get our terrain corner center point and from here we do our adjustments.

I use in_pathing_grid to find the corners of the choke so that regardless of whether there is a height difference, we still raycast down the ramp as our units can path through there.

To determine if we have a ramp choke or not, after getting the preliminary midpoint between the two corners, the code checks whether a point 3 units beyond the midpoint (away from ournat, toward the enemy) is NOT in the placement grid:

From here we do our gate position checks based on ramp or flat ground, check distance of < or > 7.5 of ramp ditsance for narrow/wide ramp. We step outward on narrow ramp and inward on wide ramp diagonally by 1 distance from wall midpoint direction from each corner towards the angle closest to our base and then we step perpendicular to the wall vector so we are stepping towards our inner by a distance of 1. Making sure we snap to half integer on each step so we always work with our grid so our final gateway positions are clean. Flat ground choke just uses stepping in by 1, then snap to half grid, then step in by 1 again and snap to find out central point for our gateways, then we calculate from those gateway points with pythagoras theorem to get our pylon pos. Cyber core then makes sure it touches gateway1edge tiles with its own edge tiles and then checks for the edge tiles of gateway2 to then leave a 1 tile gap in between it and the cyber core.

1 Like