0 votes

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:
        update_objectif(body.position)
        yield(get_tree().create_timer(get_physics_process_delta_time()), "timeout")
in Engine by (120 points)

1 Answer

0 votes
Best answer

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()
print(v_normal)
by (10,928 points)
selected by

thanks i'll try that out

it worked perfectly thanks a lot

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.