vhman
July 24, 2024, 11:29pm
1
Hello Unity
It quite a while that we notice a bug with Navigation Agent when moving in Y axis on NavMesh Surface.
opened 07:59PM - 24 Jul 24 UTC
closed 11:45AM - 25 Jul 24 UTC
I spawn agents on my nav mesh and then set their destination to a point in an ar… ray of points. The spawning of the minions looks like this:
```cs
private void CreateMinion(PlayerNumber player, UnitSO unitData)
{
Transform[] pathPoints = GetCurrentPlayerPaths((int)player);
Transform spawn = player == PlayerNumber.Player1 ? P1CreepsSpawn : P2CreepsSpawn;
GameObject newMinion = Instantiate(unitPrefab, new Vector3(pathPoints[0].position.x, spawn.position.y), Quaternion.identity);
newMinion.GetComponent<Unit>().minionAttributes = unitData;
newMinion.GetComponent<Unit>().player = (int)player;
newMinion.GetComponent<Unit>().playerPath = pathPoints;
newMinion.GetComponent<NetworkObject>().Spawn(true);
}
```
Then OnNetworkSpawn on the minions, I do this:
```cs
agent.updateRotation = false;
agent.updateUpAxis = false;
agent.speed = minionAttributes.MoveSpeed;
if (NavMesh.SamplePosition(playerPath[pointIndex].position, out NavMeshHit hit, 0.25f, NavMesh.AllAreas))
{
Debug.Log($"NAV HIT BABY: {hit.position}");
NavMeshPath path = new NavMeshPath();
bool yep = agent.CalculatePath(hit.position, path);
Debug.Log($"Path: {path.status} ({yep})");
agent.SetDestination(hit.position);
}
```
And here's what it looks like when they spawn, and I set their destination (I Debug.DrawLine their path in red): https://gyazo.com/4454aa2018fe86dfca049ec6523bb344
https://gyazo.com/b83f8991a0bd773c97fd5cb7a869ce38
Also if the movement is not vertical it seems to be fine for some odd reason: https://gyazo.com/ef588d9579f8c85fedc6377c0335f2c2 As soon as they get into vertical movment sometimes they get stuck on I don't know what...
Do you have any idea of what is going on? :O
Thanks
opened 06:21AM - 29 Nov 23 UTC
closed 07:03AM - 12 Dec 23 UTC
Hi,
I want to report an issue I found when an agent tries to move to a destina… tion that is straight up or down in relation to the agent (has the same x position). The agent appears to not move for a few seconds, then occasionally jolts in the direction of the destination, and then stops moving for a while again. If the destination or agent is offset from the identical x position by at least 0.001 (from any source), the issue is no longer present. The issue is also NOT present for agent-destination pairs with the same y position.
Someone else seems to have experienced a similar issue on the unity forums but with no solutions: https://forum.unity.com/threads/2d-navmeshagent-will-not-move-straight-up-or-down-and-other-strange-behavior.1269635/
opened 04:31AM - 07 Nov 23 UTC
closed 02:02PM - 07 Nov 23 UTC
NavMeshAgent is stuck moving vertically when calling the Move() function, even w… hen the vector passed is zero, the problem persists even after applying 'Tilt Surface' which is a stated solution.
This is the class using the agent:
```
using UnityEngine;
using UnityEngine.AI;
namespace Resources.Scripts.Player {
public class PlayerMovement : MonoBehaviour {
public bool Immobilized { get; private set; }
private NavMeshAgent _navMeshAgent;
private Vector3 _movement;
private const int PPU = 16;
private void Awake() {
_navMeshAgent = GetComponent<NavMeshAgent>();
}
private void Start() {
_navMeshAgent.updateUpAxis = false;
_navMeshAgent.updateRotation = false;
}
private void FixedUpdate() {
if (Immobilized) return;
var pixelAdjustedPosition = new Vector3(
Mathf.Round(_movement.x * PPU) / PPU,
Mathf.Round(_movement.y * PPU) / PPU,
0.0f
);
if (pixelAdjustedPosition.x == 0.0f && pixelAdjustedPosition.y != 0.0f) pixelAdjustedPosition.x = 0.0001f;
_navMeshAgent.Move(pixelAdjustedPosition * (_navMeshAgent.speed * Time.fixedDeltaTime));
}
public void Move(Vector3 to, float speed) {
_movement = to.normalized;
_navMeshAgent.speed = speed;
}
public void Immobilize() {
Immobilized = true;
}
public void Release() {
Immobilized = false;
}
}
}
```
And here are the configs for the Nav Surface + Tilemap


opened 03:18AM - 06 Sep 23 UTC
closed 07:17PM - 22 Sep 23 UTC
For some reason, if you supply a vector to NavMeshAgent.Move that has no x value… (just y), it doesn't move. I can provide x values as low as 0.00001 and it'll work fine, but anything lower, or 0, will not result in movement.
This has similarly been reported here: https://forum.unity.com/threads/navmesh-agent-the-y-next-position-y-velocity-does-not-update-if-there-is-no-x-velocity.953465/
And we can find many more complains on that.
Bug reproduced if Agent has destination that is only in Y axis. Like form (0,0,0) to (0,10,0).
Essentially agent cannot move strait Y, event if Agent and NavMesh rotated and UP is now on Z axis.
It seems some logic prevent Agent moving if there zero XZ speed.
Hi vhman,
We are aware of the issue and we’ve provided a fix for it in Unity 6 (6000.0.10f1). In the coming weeks we’ll fix it in other versions of Unity. You can check the status here: Unity Issue Tracker - Nav Mesh Agent is unable to move on the Y axis when the NavMeshSurface GameObject is rotated 90 degrees .