# Question about navMeshAgent speed and the "Time" variable

I get a weird outcome when i try to program my navMeshAgent’s speed. I want it to arrive at the target at a specific time, but somehow it manages to arrive earlier. (Although that’s not so bad, since I’m modelling bus routes, it’s nice for the bus to arrive early!)

To be more specific, lets say I have 2 gameObjects, target1 and target2. When the agent reaches target1, it gets a new destination, target2. target1 has a variable in a script called target1atts.js that’s attached to it, containing only the line:

``````var arrTime = 10.0   // arrival time for target 1
``````

Likewise, target2 has the target2atts.js script attached, containing:

``````var arrTime = 30.0   // arrival time for target 2
``````

Furthermore, using the NavMeshAgent.CalculatePath function, I know the path length between the 2 targets is 420. (Quick question here, what units is this length in?) In a script attached to the navMeshAgent, I have the following:

``````var depTime = 10.0                  //the time the agent arrived at target1
var arrTime = 30.0                  //the time the agent needs to arrive at target2
var tripDuration = arrTime - depTime
var pathLength = 420                //taken from NavMeshAgent.CalculatePath
var spd = pathLength/tripDuration   //effectively the speed for this trip, equals 21
agent.speed = spd
``````

Given that the navMeshAgent is at target1 when Time.time equals 10 (give or take some ms), it should follow that with the above calculations, it would reach target2 when Time.time equals 30 (give or take the same amount of ms). However, it consistently arrives at target2 at around 23 seconds. I would expect it to arrive later than the predetermined time, due to deceleration during turns, but in no way it should arrive earlier, or even that earlier.

I’m stumped, any clues as to what’s wrong?
I’m almost ready to hold a maths book against the screen, screaming “The power of math compels you!”

Thank you for any insight.

OK first try your experiment with a straight path … no turns. See what happens.