I have been struggeling with this for a really long time, finally giving up and asking for help. I am making a city builder with a lot of AI moving around. As part of their idle behaviour I want them to walk up to each other and start talking.
To do this I update their destination onSearchPath
with a fairly high repath rate. With each other as targets.
I have been experimenting with repath rate, pick next waypoint distance, and stopping distance. No matter what I do I cannot get consistent results. If the game was always running at x1 time scale it would not be as big an issue, but the game can also run at x2 and x3 as most other city builders.
If I use a low pick next waypoint distance, they wobble like so (especially on high time scales):
But if I pick too high value, it gets too inaccurate.
With a pick next waypoint distance of 1, and a repath rate of 0.2f it works pretty well on x1 time scale. But when I up the timescale this gets far too inaccurate, either they stop too far from each other (since I set a high stopping distance) or too close to each other and overlap.
I tried to lower the repath rate based on timescale but that didnt really help. And lowering pick next waypoint distance just creates a wobble.
I was considering simply having one of them wait and let only 1 move, but that will obviously not work for combat later when two soldiers attack each other.
Am I missing some trick here? Surely there must be some way to make this work
I use this when I have a moving target:
ai.agent.onSearchPath += UpdateDestination; //Update destination simply sets ai.destination = destination
I also set repath rate to EveryNSeconds
and base it on timescale when I have a moving target, otherwise I use dynamic:
public void SetConstantRepathRate()
{
if (agent.autoRepath.mode == AutoRepathPolicy.Mode.EveryNSeconds)
return;
AutoRepathPolicy autoRepathPolicy = new AutoRepathPolicy();
autoRepathPolicy.mode = AutoRepathPolicy.Mode.EveryNSeconds;
// I've been experimenting with a lot of different values here
if(Time.timeScale == 1)
autoRepathPolicy.interval = .3f;
else if (Time.timeScale == 2)
autoRepathPolicy.interval = .2f;
else if (Time.timeScale == 3)
autoRepathPolicy.interval = .1f;
agent.autoRepath = autoRepathPolicy;
}