My navigation agent not moving based on move_and_slide()

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Klarner

My navigation agent script doesn’t really work, and I don’t know what the reason is. Everything I’ve written so far is right, at least based from the codebases that I’ve studied. It works by manipulating the transform directly, but I want to do it with the velocity from the kinematic body through move_and_slide().

It’s even more harder to debug since there’s no other resources I can rely to regarding this problem. Note that I’ve already enabled Avoidance, and this kind of algorithm words in 2D, but somehow not in 3D.

extends KinematicBody

onready var navigationAgent = get_node("NavigationAgent")
onready var navigationServer = get_parent() # Parent must be a navigation node
onready var animationPlayer = get_node("AnimationPlayer")
onready var camera = navigationServer.get_node("Camera")

func _ready():

func _unhandled_input(event):
	if Input.is_action_just_pressed("ui_left_mouse"):
		navigationAgent.set_target_location(camera.get_mouse_world_point()) # This bit of code just gets the mouse click position.

func _physics_process(delta):
	var nextLocation = navigationAgent.get_next_location()
	var direction = global_transform.origin.direction_to(nextLocation)
	var velocity = direction * navigationAgent.max_speed

func _on_NavigationAgent_velocity_computed(safe_velocity):
	move_and_slide(safe_velocity, Vector3.UP)
:bust_in_silhouette: Reply From: Klarner

So apparently,

The height of the CollisionShape from the KinematicBody matters a lot, especially when using a capsule as the hitbox for your body. The Path Desired Distance variable of the Navigation Agent should be proportional with the height of the CollisionShape. For example, if the Path Desired Distance is 1, then the height shouldn’t exceed 2.

There’s nothing wrong with my code, it’s just there’s something wrong with my set up. So please keep in mind how you set up your environment.