0 votes

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

Godot version 3.2.3
in Engine by (327 points)

This is what I found that works:

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

2 Answers

0 votes

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:

by (278 points)
+1 vote

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.

by (90 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 Frequently asked questions and 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.