Topic was automatically imported from the old Question2Answer platform.
Asked By
Master0987
I read the gadot docs but i could understand it as the navigation demo on github is outdated every video on youtube is almost outdated or completely outdated Ive been trying to from serveral weeks now but cant figure it out.
so please help
all and any help is appreciated
You’ve posted 3 questions about the same topic in the span of 4 hours.
Please don’t spam the Q&A.
If somebody knows, they will eventually give an answer. If nobody knows, they would have to go through the same trial and error as you to give you an answer.
Thank you for a sample! I’ve been playing around with your sample for movement on the x axis.
I made a few changes to the script and was able to convert the movement to be on the x axis like below, but I imagine there is a better way than setting the enemies self as the target.
What would be an efficient way for an enemy to move back and forth on the x axis instead of targeting the player?
extends CharacterBody2D
@export var target: Node2D
@export var speed: float
@onready var agent := $NavigationAgent2D as NavigationAgent2D
var moving = false
func _ready() -> void:
pass
func _physics_process(_delta: float) -> void:
var direction = to_local(agent.get_next_path_position()).normalized()
velocity = direction * speed
if moving:
target.move_local_x(1)
func _on_timer_timeout() -> void:
moving = !moving
jukafah | 2023-03-18 18:14
You could place two Marker2Ds in your scene, each denoting the end of a path the enemy has to patrol. NavigationAgent2D has signals for when it finished/reached target, in a callback to one of those signals you can figure out which marker has been reached, and set the other marker as the new target.