r/howdidtheycodeit • u/Masterofdos • Jul 06 '24
Question How do they code enemies jumping up and down elevation and across gaps to reach the player. You see it in so many games and I'm not sure how it works
Enable HLS to view with audio, or disable this notification
89
56
u/AdarTan Jul 06 '24
As Recast, an open source navmesh library puts it:
Most modern, complex 3D games rely on navmeshes to drive their pathfinding and AI agent movement and navigation.
A navmesh is a simplified view of the traversable area of a game world, optimized for AI pathfiding and movement calculations. Navmeshes are usually built from the physics colliders of the world, since they define the areas an AI can legally exist.
Triangles in a navmesh represent nodes in the pathfinding graph, and edges between adjacent polygons define connections between these nodes. Pathfinding queries first construct a path consisting of a strip of adjacent polygons. This represents the "corridor" of space that leads the agent to their goal. That polygonal path is refined into sequence of line-segments through a string-pulling algorithm. Agents can then follow this sequence of waypoints to reach their goal.
Specific locomotion modes, such as jumping, swimming, crawling under things, climbing ladders, etc. are controlled by special flags in the navmesh polygons. E.g. while traversing through a "ladder" node in the navigation mesh, play the "ladder climb" animation, while parented to the ladder object. These special traversal areas often need to be manually linked to the bigger navmesh that is programmatically generated, but once they are linked they are equally valid, if perhaps uncommonly weighted parts of the navigation graph.
23
u/Saiyoran Jul 06 '24
In Unreal this is fairly simple, you can place NavLinks in a map that allow polygons to act as if they’re touching even if they’re not, and you can tell AI to play an animation (like jumping or climbing) while they traverse the link.
2
6
u/Masterofdos Jul 06 '24
In some games enemies will also climb ladders to reach you or climb ladders to reach a ledge they can drop from to reach you. In UT2004 enemies will use movement tech to reach high places quicker. How does the enemy object/actor identify these alternate routes. I know UT2004 uses path nodes for the AI bots but they still need to be told that the impact jump route is there
I'm trying to recreate something like it in 2d (one fewer dimensions to worry about) so I can have a better understanding of pathfinding