I've just started using Godot and obviously fail to use NavigationAgent3D
correctly. I've added a NavigationRegion
and baked a navigation mesh successfully (not too hard, though). The navigation mesh hovers the actual geometry by one cell unit, which is correct according to the Godot documentation.
In my player node I've added a NavigationAgent3D and implemented movement in the _PhysicsProcess
method (using C#, because I'm comfortable with it)
public override void _PhysicsProcess(double delta)
{
if (NavigationAgent.IsNavigationFinished())
{
AnimationPlayer.Play("Idle");
return;
}
AnimationPlayer.Play("Walk");
var currentPosition = Position;
var nextPosition = NavigationAgent.GetNextPathPosition();
LookAt(new Vector3(nextPosition.X, currentPosition.Y, nextPosition.Z));
Velocity = (nextPosition - currentPosition).Normalized() * Speed;
MoveAndSlide();
}
When implementing movement this way, the player would move to the desired position on the navigation mesh, i.e. hovers the actual ground, which might work in some cases, but not for mine.
Moving the NavigationRegion3D
downwards somehow works, but looks weird when the character moves on stairs, plus the docs say
Do not expect the NavigationMesh to perfectly follow the original surfaces. Especially navigation polygons placed over ramps will not keep an equal distance to the ground surface. To align an actor perfectly with the ground use other means like physics.
So I tried to correct the players position, but when I'm doing so, the player won't move at all. It looks as if NavigationAgent.GetNextPathPosition()
won't give the next path position, I assume because the last one is still too far away.
All of the tutorials I've watched did not really address the issues I'm facing and neither does the official documentation as far as I can tell. Having the NavigationAgent3D
within the player node seems to be the way to go according to Docs: Setup for 3D scene.
What is the correct way to have a NavigationAgent3D
with a non-floating 3D character?