ai slows done when close to player

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

here’s my ennemi code i know why it get’s slower when the player is close is just want to know how to convert a vector that looks like (200, 450) into like (1,0) or (1,1)

func update_objectif(obj_pos : Vector2):
	var dif_pos = obj_pos - position
	position += dif_pos * get_physics_process_delta_time() * ennemi_dict["bat"]["speed"]

func _on_agr_range_body_entered(body):
	is_agro = true
	while body.is_in_group("Player") and is_agro:
		yield(get_tree().create_timer(get_physics_process_delta_time()), "timeout")
:bust_in_silhouette: Reply From: jgodfrey

Hmmm… Not sure exactly what you’re looking for here. Maybe you’re just looking for a unit-length vector that’s pointing in the same direction as the original vector? If so, then…

var v = Vector2(200, 450)
var v_normal = v.normalized()

thanks i’ll try that out

ROBOTOO007 | 2020-06-13 23:49

it worked perfectly thanks a lot

ROBOTOO007 | 2020-06-13 23:58