Studio › Manual › Studio kit

Paths and agents in the game

With a navigation mesh in the room, the kit finds paths over its polygons (A*, then the shortest line through the edges crossed):

var path = nav_path(x, y, mouse_x, mouse_y);    // [[x, y, kind], …], [] when there is no way
path = nav_path_smooth(path, 24);               // round the corners (optional)
nav_points = path;
// each step:
if (!nav_follow(200)) move_and_slide();         // sets velocity_x / velocity_y toward the next point
  • nav_follow(speed, [arrive]) steers along nav_points, slows down at the end and returns true when done; it works with the kit's move_and_slide() (or x += velocity_x * studio_delta()).
  • Agents: nav_agent_init(speed, radius) in Create, nav_agent_set_target(x, y), nav_agent_step() each step. Agents find the way again now and then and avoid each other: one they would meet in the next nav_avoid_time seconds (0.75) is passed on the side away from where they would be closest; agents that overlap are pushed apart.
  • nav_mesh_exists(), nav_path_length(path), nav_mesh_path(x1, y1, z1, x2, y2, z2); 3D: nav_path_3d(...) and nav_agent_init(speed, radius, true).

Keys are shown as on the Mac: ⌘ Command, ⌥ Option, ⌃ Control, ⇧ Shift. Studio for Windows shows its own keys beside each menu item.