how can I write the movement of the mob towards the player?

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

how can i write the movement of the mob towards the player? how can i write the movement of the mob towards the player? I’m new to development and I have no idea why the mob doesn’t move on startup.

    extends KinematicBody2D

export var mob_speed = 400
var velocity = Vector2()
var target


func _ready():
	var target = get_tree().current_scene.get_node("Player")
	var velocity = (target.position - position).normalized * mob_speed

func _process(delta):
	velocity = move_and_slide(velocity)
:bust_in_silhouette: Reply From: Wakatta

Velocity needs to be updated and you re-initialize it in the _ready() function

extends KinematicBody2D

export var mob_speed = 400
var velocity = Vector2()
var target


func _ready():
    target = get_tree().current_scene.get_node("Player")

func _process(delta):
    velocity = (target.position - position).normalized * mob_speed * delta
    velocity = move_and_slide(velocity)