Some context on what I’m building:
I’m using the pathfinding for NPC agents that have a schedule. When the player enters a scene, the NPC will have a start point and a target point. For example, at 10:00 in-game time, the NPC should be at the station. He starts walking to the station from his house at 9:00. So every time at 9:00, this NPC will calculate a path to the target point and start walking there. Because there are dynamic obstacles, I can’t re-use one path and have to calculate one every time. This process is working perfect with this package.
But now I have a challenge. What if the player enters the scene at 9:30 in-game time?
My own solution (not implemented yet) is a bit messy:
I check that the NPC had a total 60 minute travel time from start to end and he has 30 minutes left, so he should be 50% of the way to his target. So I take the end point and calculate a random path to a point thats roughly 50% of the distance between start/end based on movespeed, remaining time and total distance from start to end. Then from this random point that’s roughly 50% away of the target, I can calculate a new path to the target. But my problem is that the random point at 50% of the distance is never accurate.
What would be perfect, but I don’t know if it’s possible:
When the player enters the scene at 9:30. The NPC agent will know it’s start position and end position. The “normal” path will be calculated from start to end. Then we know he should actually be at 50% of the way again. But this time, we use the original start -> end path and we move the agent to a waypoint that’s 50% of the path length. But I don’t think there is a way to determine the length of a path or put a point on e.g. 50% of 70% of the way in the path.
I hope I gave enough context for my problem. Would appreciate any feedback if you guys have had the same issue before or know of some potential solutions.