How to make a zombie follow the player?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By ismaelgame7
:warning: Old Version Published before Godot 3 was released.

Hello,

I’m trying to make a zombie follow the player only on the X axis, Look:

extends KinematicBody2
var zumbie = self
var speed = 2
onready var target = get_parent().get_node("Player")
func _ready():
   set_fixed_process(true)
pass

func _fixed_process(delta):
var direction = (target.get_global_pos().x - zumbie.get_global_pos().x).normalized()
move(direction*speed) 
pass

But gives this error: Invalid call. Nonexistent function ‘normalized’ in base ‘float’.

Can someone help me?

:bust_in_silhouette: Reply From: YeOldeDM

normalized() is a function to call on vectors. You are taking only the x values of your vectors (which are float). Remove the .x part of your positions and it should work.

If you want the thing to follow only on the x axis, eliminate the y value before applying the motion.

func _fixed_process(delta):
var direction = (target.get_global_pos() - zumbie.get_global_pos()).normalized()
direction.y = 0
move(direction*speed) 

YeOldeDM | 2017-04-03 00:28

thank you! :smiley:

ismaelgame7 | 2017-04-03 00:43