Godot Version
4.2.1 (Steam)
Question
I am running into some issues following some 3D navigation tutorials. I am trying to have my robot enemy follow the player around, but for some reason instead of going to the next navigation point, it is trying to go straight to the player, meaning if there is a wall in between the player and robot, the robot will not navigate around the wall and will keep pushing against the wall. I have the navigation debug on, and the red lines do try to navigate the robot around walls, but the robot simply does not follow this line for some reason.
My level script, with a navigationregion3D base node:
extends NavigationRegion3D
@onready var player = $Player
func _physics_process(delta):
get_tree().call_group(“enemy”, “update_target_location”, player.global_position)
My enemy script, with a characterbody3D base node:
extends CharacterBody3D
@onready var animator = $AnimatedSprite3D
@onready var audio = $AudioStreamPlayer
@onready var navagent : NavigationAgent3D = $NavigationAgent3D
@export var HEALTH = 100
@export var SPEED = 3.0
var gravity = ProjectSettings.get_setting(“physics/3d/default_gravity”)
var hurting = false
var dead = false
var readytonav = false
func _ready():
animator.play(“idle”)
await get_tree().process_frame
readytonav = true
func _physics_process(delta):
# Add the gravity.
if not is_on_floor():
velocity.y -= gravity * delta
if HEALTH <= 0:
die(delta)
if readytonav and not dead:
var direction = ( navagent.get_next_path_position() - global_position).normalized()
translate(direction * SPEED * delta)
velocity = velocity.move_toward(direction,.25)
move_and_slide()
func update_target_location(target_location):
navagent.target_position = target_location
func die(delta):
dead = true
animator.play(“hurt”)
audio.play()
await get_tree().create_timer(50 * delta).timeout
queue_free()
Screenshot in-game: