get_simple_path and move_and_slide

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

Hello,

I have some problems with this code:

It finds the path between a Player and an Ennemy, both are KinematicBody like this:

KinematicBody
→ Skeleton
–>–>MeshInstance
→ AnimationPlayer
→ CollisionShape

The floor is a Gridmap

There is also a Navigation like this:

Navigation
→ NavigationMeshInstance
→ ImmediateGeometry # Just to test the path

I use “Bake NavMesh” with the floor as child then move the floor out the Navigation

All is working well, the Enemy find and follow the path to the Player except he is not on the ground, he is floating a little above…

Any idea???

This is part of my code:

Thank you…

func FollowPlayer(delta):
	
	var Monster =  global_transform.origin
	var Player = Player.global_transform.origin
	
	if(NavTimer.get_time_left() == 0):
		PathPoints = Nav.get_simple_path(Monster, Player)
	
		if(PathPoints.size() < 2):
			PathPoints = []
		else:
			DrawPath(PathPoints)
		NavTimer.start(NavTime)

	if (PathPoints.size() > 0):

		var move_vec = (PathPoints[0] - Monster)
		if move_vec.length() < 0.1:
			PathPoints.remove(0)
		else:
			move_and_slide(move_vec.normalized() * Speed * delta, Vector3(0, 1, 0))
			look_at(PathPoints[0], Vector3(0, 1, 0))
			rotation_degrees.y = 180+rotation_degrees.y
:bust_in_silhouette: Reply From: Magso

move_and_slide needs a -y value to resemble gravity.

move_and_slide((move_vec.normalized() * Speed) + Vector3.DOWN * delta, Vector3(0, 1, 0))