Simple navigation agent floating on slopes.

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

Hello!

Sorry if this is a stupid question.
I am running the current version of Godot and I have come across an issue with my navigation.

It’s a pretty simple “follow the player scenario”, everything works well unless the “AI” has to traverse a slope. On the beginning of a slope it floats over ground and then on the top of a slope it sinks underground.

I have tried changing the NavMesh properties multiple times but I have not found a solution.

I am attaching the agent code and the shape itself is a simple capsule.

Is there a way to keep the agent grounded at all times or is there any other/better way to do the 3D navigation?

extends KinematicBody
 

var player = null

var can_move = true

var path = []
var path_ind = 0
var move_speed = 3
onready var nav = get_parent()

func _process(delta):
	if Input.is_action_just_pressed("debug_1"):
		can_move = false
	if Input.is_action_just_pressed("debug_2"):
		can_move = true

func _physics_process(delta):
	if can_move == true:
		if path_ind < path.size():
			var move_vec = (path[path_ind] - global_transform.origin)
			if move_vec.length() < 1:
				path_ind += 1
			else:
				move_and_slide(move_vec.normalized() * move_speed, Vector3(0, 1, 0))
	
	
		transform.origin.y = $RayCast.get_collision_point().y
 
func move_to(target_pos):
	path = nav.get_simple_path(global_transform.origin, target_pos)
	path_ind = 0


func set_player(p):
	player = p


func _on_Timer_timeout():
	move_to(player.global_transform.origin)