+1 vote
func _physics_process(delta):
    #if the the enemy has reached the end of the current path create a new path
    if counter > path.size()-1:
        counter = 0
        path = get_parent().get_node("Map").get_simple_path(get_translation(), get_parent().get_node("Player").get_translation())

    var enemyPos = get_translation()

    var vector = Vector2(path[counter].x - enemyPos.x, path[counter].z - enemyPos.z)
    #finds the distance to the goal
    var distancesq = vector.length_squared()
    vector = vector.normalized()

    set_linear_velocity(Vector3(vector.x, 0, vector.y)*speed)
    set_translation(Vector3(enemyPos.x, 1, enemyPos.z))

    #checks to see if its roughly near the current path point if so advances the path
    if((enemyPos.x >= path[counter].x-precision && enemyPos.x <= path[counter].x+precision) && (enemyPos.z >= path[counter].z-precision && enemyPos.z <= path[counter].z+precision)):
        counter += 1

an example of the jagged movement

The code above is the only code directly manipulating the purple enemy model. I have attempted to use the impulse method rather then the linear movement but i never managed to achieve the needed results(i couldn't get it to even follow the path). How can i make this movement smoother? I have little experience in this specific engine, any help would be appreciated!

in Engine by (13 points)

I haven't played with rigid bodies yet and am more familiar with kinematic ones.

Looking at the code, not sure why you are setting the transform of the physics body. My understanding is that rigid bodies should be moved via force alone.

Regarding the jagged movement, I think you need to call the linear_interpolate function to get the next point to move to rather than the next point in a path.

Why bother use RigidBody at all when you can just use a KinematicBody. Unless you are enemy will be affected by Godot's physics engine. In such a case you could try switching the mode of the RigidBody from Rigid to Kinematic.

Please log in or register to answer this question.

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.