#How do you make Ai enemies and pathfinding
1 messages · Page 1 of 1 (latest)
Following these tips will increase your chance of getting good answers:
Helpers need to know as much as possible about your problem. Try answering the following questions:
- What are you trying to do? (show your node setup / code)
- What is the expected result?
- What is happening instead? (include any error messages)
- What have you tried so far?
Helpers often ask you questions to better understand your problem. Not answering them or saying "it's not relevant" is not helpful. Even if it is not directly relevant, there is a high chance the answer will give more context for the people that are helping you.
Please don't expect people to immediately help you. We all do this in our freetime. It may take some time until someone who can help you will answer.
What have you tried so far?
What's going wrong? Can you share the code you're using?
every time i follow the instructions of the video the enemy just doesnt follow me
Okay. Can you share the code you're using?
I'm not seeing anything about navigation... This is just a player controller script. I'm asking for the code you tried to follow with the tutorial, but wasn't working
oh ok
extends CharacterBody3D
@export var move_speed: float = 4.0
@onready var navigation_agent: NavigationAgent3D = $NavigationAgent3D
var player: CharacterBody3D = null
func _ready() -> void:
var players = get_tree().get_nodes_in_group("player")[0]
func _process(delta: float) -> void:
navigation_agent.set_target_position(player.global_position)
func _physics_process(delta: float) -> void:
if navigation_agent.is_navigation_finished():
return
var next_position: Vector3 = navigation_agent.get_next_path_position()
velocity = global_position.direction_to(next_position) * move_speed
move_and_slide()