0 votes

I'm programming a boss that I want to be able to jump on the player. I want to set his X velocity based on how far away he is from the player. The farther away, the faster he travels horizontally. What's the best way to calculate this?

in Engine by (197 points)

1 Answer

0 votes

Use distance to multiplied by speed.

overall_speed = boss.distance_to(player.position)*speed

and use overall_speed variable. Don't put this in _process because distance_to will cause it to slow down .

You could also use lerp.

boss_pos = boss.position

while time < 1:
    boss.position = lerp(boss_pos, player.position, time)
    time += speed
    yield(get_tree(), "idle_frame")
by (3,211 points)
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.