Godot Version
4.5.1
Question
I have a preexisting project that broke when i upgraded and i’m trying to figure out how to do the same thing in the latest version. I simply want a characte to move between a marker to another marker and back again.
I have some really simple code. A tilemap layer with navigation on it, and some without. I want the character to move around the area that does not have navigation and reach point 2.
All it does is goes back and forth and gets stuck.
Any help would be great.
Thanks
extends CharacterBody2D
var navigation_target_name = 'Marker2'
var speed = 50
@onready var nav_agent: NavigationAgent2D = $NavigationAgent2D
@onready var marker_1: Marker2D = $"../Marker1"
@onready var marker_2: Marker2D = $"../Marker2"
func _ready() -> void:
get_marker_position()
func _physics_process(delta: float) -> void:
if nav_agent.is_navigation_finished():
get_marker_position()
else:
var current_agent_position = position
var next_path_position = nav_agent.get_next_path_position()
var new_velocity = current_agent_position.direction_to(next_path_position) * speed
velocity = new_velocity
move_and_slide()
func get_marker_position():
if navigation_target_name == 'Marker1':
navigation_target_name == 'Marker2'
nav_agent.target_position = marker_2.position
else:
navigation_target_name == 'Marker1'
nav_agent.target_position = marker_1.position
print('move to ' + navigation_target_name)
