smoother look_at() in 2D

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

I would highly appreciate the shortest and the easiest way of achieving smoother look_at() (2D) to avoid instant sharp movements.

This is what I found that works:

#player.rotation = lerp_angle(#player.rotation, (#look-at-object.global_position - #player.global_position).normalized().angle(), #weight)

Suleymanov | 2021-04-10 21:46

1 Like
:bust_in_silhouette: Reply From: Legorel

I think you should use some interpolation somewhere in your code, I never done it by myself so you’ll have to do it on your own
Here is the doc for you:

:bust_in_silhouette: Reply From: loipesmas

Something like this should work:

var angle = (target - self.global_position).angle()
self.global_rotation = lerp_angle(self.global_rotation, angle, delta)

Where target is the point (in global cooridnates) you want to look at. You can multiply delta by some value to make it faster/slower. You can use local coordinates instead of global, whatever suits your needs.

1 Like