PathBerserker2d  1.0
Platformer pathfinding solution
NavAgent's build-in movement

PathBerserker comes with 2 components, which implement NavAgent movement. These are: "TransformBasedMovement" and "CorgiBasedMovement". A NavAgent without either one of these components attached will still be able to pathfind, but won't move along the path.

To use "CorgiBasedMovement", you must own CorgiEngine (https://corgi-engine.moremountains.com/) and have it imported. More about PathBerserkers Corgi integration here: Corgi

TransformBasedMovement

TransformBasedMovement is Pathberserker's own movement solution. It works by directly manipulating the transform of a NavAgent and allows for very precise movement. It's main drawback is, that there is no physics interaction between a NavAgent and its environment. There is nothing stopping a NavAgent from moving through a collider.

TransformBasedMovement implements movement for segments and links. Segments, which represent movement on the ground are traversed by simple lerping between start and goal.

Links are traversed depending on their type. Following are the build-in link types.

  • Corner
    The agent rotates to align with the next segment's normal.
  • Fall
    The agent accelerates towards the link's goal.
  • Jump
    The agent moves with a constant x-velocity, while its y position follows a sine-wave. This gives the jump characteristic upwards then downwards movement. The sine-wave's amplitude is based on this distance of the jump.
  • Teleport
    The agent's position is instantly set to the links goal.
  • Climb
    Climbing happens in 3 phases. First the agent moves on the x axis to the link's transform position. Then the agent moves on the y axis towards the link's goal y value. Finally the agent moves again on the x axis towards the link's goal x value. This and elevator are the only two link types that care about the link's x position important.
  • Elevator
    Much like climb, except that the agent does not move on the y axis on its own, but instead waits for the elevator to bring it to the correct y level.

Overriding the build-in movement

You are free to implement your own movement handler, if the build-in's don't fit your usecase. For inspiration, please look at the source code for TransformBasedMovement and CorgiBasedMovement.

The NavAgent has an internal pointer, that keeps track of where the NavAgent is on its calculated path. A movement handler must implement moving the NavAgent to its current PathSubGoal and then call either CompleteSegmentTraversal or CompleteLinkTraversal to advance the NavAgents internal path pointer to the next subgoal.

A custom movement handler can make use of the following NavAgent events.

  • OnStartLinkTraversal Called only once, after a NavAgent starts to traverse a link. Use it to initialize variables needed to execute the link traversal.
  • OnLinkTraversal Called every update, when a NavAgent is on a link. Add your link traversal logic here. Call CompleteLinkTraversal when you have completed the link traversal, to let the NavAgent move to the next PathSubGoal.
  • OnStartSegmentTraversal Called only once, after a NavAgent starts to traverse a segment. Use it to initialize variables needed to execute the segment traversal. -OnSegmentTraversal Called every update, when a NavAgent is on a segment. Add your segment traversal logic here. Call CompleteSegmentTraversal when you have completed the Segment traversal, to let the NavAgent move to the next PathSubGoal.