0 votes


I have some problems with this code:

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

--> Skeleton
-> AnimationPlayer
-> CollisionShape

The floor is a Gridmap

There is also a Navigation like this:

--> 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 = []

    if (PathPoints.size() > 0):

        var move_vec = (PathPoints[0] - Monster)
        if move_vec.length() < 0.1:
            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
in Engine by (19 points)

1 Answer

0 votes

move_and_slide needs a -y value to resemble gravity.

move_and_slide((move_vec.normalized() * Speed) + Vector3.DOWN * delta, Vector3(0, 1, 0))
by (3,247 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.