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?

asked Oct 8, 2019 in Engine by 9BitStrider (166 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")
answered Oct 8, 2019 by Magso (2,505 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.