2

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)

` 1 See the image of my code here.

I can't work out if I'm doing something really stupid as I'm fairly new to Godot. Any help would be massively appreciated!

will.web
  • 23
  • 1
  • 3
  • Does this answer your question? [How to LERP between 2 angles going the longest route or path in Godot](https://stackoverflow.com/questions/68875814/how-to-lerp-between-2-angles-going-the-longest-route-or-path-in-godot) – Theraot Sep 23 '21 at 22:47

1 Answers1

2

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 :)