I’m using multiple NavMeshAgent objects that run parallel to one another in the same direction (no collision, similar destination set along their own respective paths). Everything works fine except it doesn’t appear that Unity is respecting decimals beyond a tenth.
Their speeds are separated by hundredths or thousandths (6.6145 vs 6.6389, for example). One should clearly beat the other to the destination. However, it doesn’t seem to be working that way.
If I log speed to console, it shows the proper full value but velocity is always rounded to tenths so both show velocity of (0.0, 0.0, 6.6).
I have next to no acceleration impacting anything (it’s set to 100 to get them up to speed immediately) and I have also tried manually setting velocity with the same speed value but it doesn’t seem to make a difference. I’ve seen several references that show this can be done but I’m baffled as to how the slower of the two performs the same as the faster object.
I think you don’t appreciate how tiny that delta is. Even the slightest hesitation or path cornering distance would probably eat it right up.
However, in a straight line the navmesh system works fine, and after 300 units of travel, the faster agent is approximately one unit ahead of the slower agent, and I even put two other agents between those speeds, and they all space out as expected, about a third of a unit apart after 300 units of motion.
See for yourself in the attached unitypackage.
Always run the numbers. Trust the numbers, never the politicians!
I do understand it’s a very tiny amount, for sure, but this does take place over a long distance so it works out to a further distance apart.
Thank you for taking the time with this, it’s greatly appreciated!
I’m not sure if there must be something else that I am missing that’s causing this to happen. The objects follow a straight path with no collisions, fast acceleration and it doesn’t seem to make a difference - I wind up not getting the intended result.
Originally, I used two speeds - one for one half of the distance, another for the other. They’d average to the aforementioned speeds but the slower would always prevail. I’ve tried making it just the average speed for the entire duration and it still does the same thing. Very frustrating!
how big a speed delta do you need it to be to see a difference?
is something an integer along the way your choice of speed flows within your code, so that 6.1 becomes 6 and 6.2 also becomes 6?
if you pause and look at the navmesh agent, what does the Steering: Speed value read at in the inspector? Mine reads clearly different per agent, right down to the 4th decimal place
is there perhaps an uneven speed penalty/bonus for going on uneven ground (uphill)?
is there a rigidbody on your navmesh items and does that rigidbody have drag/angularDrag?
do you have any other code limiting the speed artificially, so that both are capped at a lower speed?
You’re just experiencing a display issue with Vector3.ToString()'s implementation.
If you print out a Vector3 using Debug.Log (or any other means of converting a Vector3 to a string), it’s going to round it to 1 decimal place. That’s just how the value is displayed. It doesn’t mean that’s what the value actually is.
Try multiplying the velocity by 1000 just to convince yourself the precision isn’t being lost. Or print out velocity.x/velocity.y/velocity.z components individually.