Navigating instances to a target
To calculate or update the path to the target instance, we need to add more code to the renderer. We start by adding the code to compute the actual path from an instance to the target position.
Calculating the path to the target
The best place for the path update code is in the loop over all animated instances in the draw()
call of the renderer class OGLRenderer.cpp
or VKRenderer.cpp
, right after the ground and collision detection code that was just copied for the non-animated instances. We have the final world position of the instance available, including any gravity updates, and can use this position as the starting point of the path-finding algorithm.
First, we check if navigation is enabled for the instance and get the instance index of the target:
if (instSettings.isNavigationEnabled) {
int pathTargetInstance =
instSettings.isPathTargetInstance;
Then, we do a sanity check of the target instance to avoid...