will.web
will.web

Reputation: 53

Smooth look_at() in Godot

I am working in GDScript, and I'm trying to get the player to aim their weapon in the direction of the mouse cursor. The look_at() function is great, but it's not the smooth movement I'm looking for.

So, instead I've been experimenting with the lerp() math operation to make it smooth... but its very jittery and buggy movement which is obviously not ideal.

func _process(delta):

        rotation_degrees =  lerp(rotation_degrees,rad2deg(get_angle_to(get_global_mouse_position())),aim_speed)

See the image of my code here.

How to resolve this?

Upvotes: 4

Views: 7922

Answers (1)

Rikith Reddy
Rikith Reddy

Reputation: 46

Please use_physics_process() instead of _process()

_process runs at the fastest possible rate whenever it gets the CPU. That makes it jittery. It is not ideal for player movements since you will need consistency in your frames.

_physics_process() is consistent as it is frame independent and is ideal for player movement.

if you want more details I recommend you check this video by Godot Tutorials

Btw look_at() should work just fine :)

Upvotes: 3

Related Questions