Description
Describe the project you are working on
A top-down game, with automation of combatants through player made behavior trees.
Describe the problem or limitation you are having in your project
I'm making movement code for my top down characters, and I keep finding that Vector2 move_toward()
function is handy when moving kinematic bodies towards a point, but making them look at a point smoothly is hard.
look_at snaps something instantly, which isn't desired in this case.
Implementing and getting the wrapping logic took a chunk of brain power, to make sure it wasn't going to have subtle bugs with larger rotations, or negative ones.
Describe the feature / enhancement and how it helps to overcome the problem or limitation
Adding two functions to the core GDScript namespace, with the following WIP names.
rotate_toward(angle_a, angle_b, amount)
:
This takes three angles as floats, and returns angle_a, rotated towards angle_b, by amount, or less if angle_b can be reach in less than amount. This would perform wrapping around TAU, and moving along the shortest arc between a and b.
rotate_toward_degrees
would be as above, but wrapping around 360 degrees instead, and could potentially be omitted.
Describe how your proposal will work, with code, pseudo-code, mock-ups, and/or diagrams
Consider a topdown games turret. Having it move smoothly to look at a target could thus be.
var target_angle = (target_position - global_position).angle()
$TurretBase.global_rotation = rotate_toward($TurretBase.global_rotation, target_angle, turret_turn_speed)
Similar example could be used for top down vehicles, or burrowing/flying platformer enemies.
If this enhancement will not be used often, can it be worked around with a few lines of script?
It wouldn't be hard to write around with scripts, but it would be easy to get subtly wrong, and would potentially have to be repeated in many file throughout a project.,
Is there a reason why this should be core and not an add-on in the asset library?
Importing an add-on for this would be comparable to the amount of work required to do it in the first place. This aims to solve a papercut, like #42976 did.
Bugsquad edit, search terms: move_towards_angle