Hello! I need some help on how to make the enemy chasing the player! My game is a first person game and trying to make the enemy follow the player and used this tutorial

by Miziziziz and it's the kinda of enemy that I need though the code is not working. Theres no errors those the enemy doesn't chase the player

extends KinematicBody

const MOVE_SPEED = 3

onready var raycast = $RayCast
#onready var anim_player = $ANimationPlayer

var player = null
var dead = false



# Declare member variables here. Examples:
# var a = 2
# var b = "text"


# Called when the node enters the scene tree for the first time.
func _ready():
	pass # Replace with function body.

func _physics_process(_delta):
	if dead:
		return
	if player == null:
		return
	var vec_to_player = player.translation - translation
	vec_to_player = vec_to_player.normalized()
	raycast.cast_to = vec_to_player * 1.5	
	
	#move_and_collide(vec_to_player * MOVE_SPEED * delta)
	
	if raycast.is_colliding():
		var coll = raycast.get_collider()
		if coll != null and coll.name == "Player":
			coll.kill()
func kill():
	dead = true
	$CollisionShape.disabled = true
	
	
		
func set_player(p):
	player = p  

@"Peter Parker" said:

extends KinematicBody

const MOVE_SPEED = 3

onready var raycast = $RayCast
#onready var anim_player = $ANimationPlayer

var player = null
var dead = false


# Declare member variables here. Examples:
# var a = 2
# var b = "text"


# Called when the node enters the scene tree for the first time.
func _ready():
    pass # Replace with function body.

func _physics_process(_delta):
    if dead:
        return
    if player == null:
        return
    var vec_to_player = player.translation - translation
    vec_to_player = vec_to_player.normalized()
    raycast.cast_to = vec_to_player * 1.5	

    #move_and_collide(vec_to_player * MOVE_SPEED * delta)

    if raycast.is_colliding():
       var coll = raycast.get_collider()
       if coll != null and coll.name == "Player":
           coll.kill()
func kill():
    dead = true
    $CollisionShape.disabled = true

func set_player(p):
    player = p

Fixed! For those who are having a hard time reading the post above. ;)

Edit: Looks like he fixed it :)

Also the lack of movement might have something to do with line 30. ⬆️

By that I mean you commented out the line that's responsible for actually moving the enemy! ?

3 years later