![]() |
Attention | Topic was automatically imported from the old Question2Answer platform. |
![]() |
Asked By | Newby |
I have a zombie enemy that chases the player as long as nothing obstructs its view i made a script that would let it continue its path to the last location where the player was “seen” by the zombie and stop.
It does it but not properly, so currently it goes the the last location but when it reaches it, it spazes out turning left and right.
The problem i found is that the position of my zombie and last_location aren’t whole numbers so the elif statement doesnt work every time.
Here is the chase and late_location script, its in a separate script for enemy entities.
func chase_player():
var to_player = player.global_position - global_position
to_player = to_player.normalized()
last_location = player.global_position
global_rotation = atan2(to_player.y, to_player.x)
movement(to_player, SPEED)
func last_location():
var to_player = last_location - global_position
to_player = to_player.normalized()
global_rotation = atan2(to_player.y, to_player.x)
movement(to_player, SPEED)
here is how i call it in my zombie scene
func _physics_process(delta):
if can_see_player:
chase_player()
elif global_position != last_location:
chase_player()
Ive been looking thought the docs about how Vector work but they don’t have a lot of example on how the methods work.
I tried using floor() and ceil() but they are for single float numbers.
Is there a way to get whole numbered vectors?