The Godot Q&A is currently undergoing maintenance!

Your ability to ask and answer questions is temporarily disabled. You can browse existing threads in read-only mode.

We are working on bringing this community platform back to its full functionality, stay tuned for updates. | Twitter

0 votes

the code:

extends CharacterBody2D
const speed = 200

@export var player: Node2D
@export var marker: Node2D
@onready var nav_agent := $NavigationAgent2D as NavigationAgent2D

func _physics_process(_delta: float) -> void:
    var dir = to_local(nav_agent.get_next_path_position()).normalized()
    velocity = dir * speed

func makepath() -> void:
    if Golbal.marker_finder == 0:
        nav_agent.target_position = player.global_position
        nav_agent.target_position = marker.global_position

func _on_timer_timeout():

func _on_area_2d_body_entered(body):
    if body.is_in_group("player"):

        Golbal.marker_finder -= 1

func _on_area_2d_body_exited(body):
    if body.is_in_group("player"):

        Golbal.marker_finder += 1
Godot version 4.1
in Engine by (25 points)

@spaceyjase - you can always copy/paste this to an answer and then Hide the original comment... That'd actually be preferable for the board, since the question does have an answer... :)

1 Answer

0 votes
Best answer

There's nothing here to stop the agent when it reaches its destination; likely the shaking is because it's constantly trying to move to another position that it never quite reaches, thus continues to make small changes and the cycle continues...

A way to stop this is to add something similar:

var distance_to_next_step = transform.origin.distance_to(dir)   
if distance_to_next_step < DISTANCE_THRESHOLD:
by (1,406 points)
selected by
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.