+1 vote

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?

in Engine by (150 points)

1 Answer

+2 votes
Best answer

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.

by (1,330 points)
selected by

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) 

thank you! :D

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.