- Home /
Pathfinding over a dynamically deforming mesh
I have a mesh that I'm programmatically moving its vertices around. I've attached some waypoints to these vertices (so, the waypoints are moving around as well) and I'm trying to get and object to move from one waypoint to the other (I'm using SeekSteer at the moment). The pathfinding seems to be working, but the object is moving through the mesh at points because the path was calculated when the previous waypoint was in a different location.
This could probably be fixed with physics and collision detection, but I am trying to avoid that as this is targeted for mobile and recalculating the mesh collider of the deforming mesh every frame would be expensive.
I imagine that this could also be fixed with the targetHeading and currentHeading calculations in FixedUpdate() in SeekSteer (to recalculate the location of the previous waypoint, I guess?), but I'm a bit stumped.
function FixedUpdate() {
targetHeading = waypoints[targetwaypoint].position - xform.position;
currentHeading = Vector3.Lerp(currentHeading,targetHeading,damping*Time.fixedDeltaTime);
}
Seems like recalculating the path more frequently would work. Gotta find that sweet spot with the time between calculations to limit mesh penetrations.