![]() |
Attention | Topic was automatically imported from the old Question2Answer platform. |
![]() |
Asked By | Mydaz |
I’m trying to make the enemies follow my player, but he doesn’t walk, any suggestions.
This is the code
extends Area2D
export (int) var SPEED
onready var target = get_node(“Sprite”)
func _ready():
pass
func _process(delta):
move_goblin(delta)
func init(pos):
position = pos
func move_goblin(delta):
if target != null:
var target_position = target.position
look_at(target_position)
var direction = (target_position - position).normalized()
var motion = direction * SPEED * delta
position += motion
Have you thought of making the goblin enemy a KinematicBody2D
node, and using the move_and_slide()
function? Failing that, have you tried using a Navigation2D
node to move the Goblin towards the player?
Ertain | 2019-11-27 00:58