Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | CupOfTea134 |
So, I have two KinematicBody2D
nodes, the Player, and the enemy. I want the enemy to be able to move towards the player, but with the way that I’m doing it (move_toward()
), the enemy completely ignores the StaticBody2D
nodes (walls / ground) and just goes right through them. My code is below (Sorry about indents, I’m new to the Q&A and don’t know how to correctly do them):
extends KinematicBody2D
var motion = Vector2()
var player
func _enter_tree(): player = get_node("/root/Level1/Player")
func _physics_process(_delta):
look_at(player.position)
position.x += move_toward(position.x, player.position.x, player.speed)
position.y += move_toward(position.y, player.position.y, player.speed)