![]() |
Attention | Topic was automatically imported from the old Question2Answer platform. |
![]() |
Asked By | Millard |
I tried following Garbaj’s basic enemy pathfinding code, but even though I’m pretty sure I’ve copied his code exactly my enemies aren’t moving. This is my code for the enemy:
extends KinematicBody
onready var navigation = get_parent()
onready var player = $"../Player"
var health = 20
var speed = 10
#ai variables
var path = []
var path_node = 0
func _ready():
pass
func _physics_process(delta):
if path_node < path.size():
var direction = (path[path_node] - global_transform.origin)
if direction.length() < 1:
path_node += 1
else:
move_and_slide(direction.normalized() * speed, Vector3.UP)
print("moving")
func move_to(target_pos):
path = navigation.get_simple_path(global_transform.origin, target_pos)
path_node = 0
print("moving to")
func _on_UpdatePath_timeout():
move_to(player.global_transform.origin)
the node structure in my scene goes like this:
Spatial
->Navigation
->->NavigationMeshInstance
->->->CSGCombiner
->->->->ABunchOfCSGMeshes
->->Player
->->Enemy
I ran some print functions to do some testing, and while move_to() is being called correctly, the else statement which the move_and_slide() code is on is not being run at all unless the player is moving. As soon as the player stops moving the else statements stops running, but the enemy doesn’t move an inch either way.
I have no idea what’s going wrong, and I really appreciate any help.
Hey don’t have much info, but
- check if the timer function is actually connected
- Is the nav mesh actually visible in editor setting
umma | 2022-05-26 00:34
Yes the signal is connected, and I can see the navmesh in the editor. =D
Millard | 2022-05-26 16:39