[SOLVED]enemy follow player

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By aleoli669

I can not get the enemy to follow the player, my script is:

extends KinematicBody2D
var zom = self
var speed = 100
onready var obj = get_parent().get_node("jugador")
func _ready():

func _fixed_process(delta):
	var dir = (obj.global_position - zom.global_position).normalized()

the enemy does not move, he remains completely still. please help!

:bust_in_silhouette: Reply From: kidscancode

In Godot 3.0, the fixed_process() function was renamed to _physics_process(). You also don’t need to enable it in _ready() as it’s auto enabled. Finally, you’ll want to multiply your velocity by delta or your speed will be 100 pixels per frame, which is going to be much too fast:

extends KinematicBody2D

var speed = 100
onready var obj = get_parent().get_node("jugador")

func _physics_process(delta):
    var dir = (obj.global_position - global_position).normalized()
    move_and_collide(dir * speed * delta)

thanks man, that problem had me stranded

aleoli669 | 2019-02-11 17:27

So if you wanted the enemy to play an animation when moving where do you put the code

Ogeeice | 2019-07-14 16:58

Thank you so much! I’ve been trying to watch tutorials and read articles but I just couldn’t find it, till this post!

Colossal_Dev | 2020-04-25 05:13