Smoothing camera movement with lerp()
Asked Answered
D

6

0

Hello, everyone, I have this really simple camera script which moves the camera as player moves its mouse (duh) but this thing is I found out in the internet that there is this lerp() function that can make things even smoother, the problem is that I cant implement in my code.

Any tips?

Here is the code for camera

func _ready() -> void:
  Input.mouse_mode = Input.MOUSE_MODE_CAPTURED
	
func _input(event: InputEvent) -> void:
  if event is InputEventMouseMotion:
    player.rotate_y(-deg_to_rad(event.relative.x * sensitivity))
    fps_camera_root_x.rotate_x(-deg_to_rad(event.relative.y * sensitivity))
    fps_camera_root_x.rotation_degrees.x = clamp(fp_scamera_root_x.rotation_degrees.x, -70, 80)

But I want to smooth this with lerp, I've read the documentation and tried to implement, here is the code now

func _physics_process(delta: float) -> void:
	fps_camera_root_y = fps_camera_root_y.rotation.x.lerp(event, delta * sensitivity)
. . .

And I get this error

How am I supposed the get all of this working? The FPS movement is working just fine, only the lerp its not.

Demp answered 27/11, 2023 at 14:8 Comment(0)
M
0

Demp What do you mean by "make things even smoother"?

Monzonite answered 27/11, 2023 at 14:21 Comment(0)
D
0

Monzonite

Hello, xyz, good to see you again. I mean it by making the camera movement smoother when moving the mouse around.

Demp answered 27/11, 2023 at 15:13 Comment(0)
J
0

Demp 'lerp()' isn't a member function for type float. It's a global scope function. The error message is telling you that you can't call ...rotation.x.lerp() b/c member 'x' (of type float) doesn't have such a function. Instead you need to call lerp as a stand-alone function. Your code should be something like:

fps_camera_root_y = lerp( <from>, <to>, <weight> )

https://docs.godotengine.org/en/stable/classes/[email protected]#method-descriptions

Jourdan answered 27/11, 2023 at 16:7 Comment(0)
D
0

Jourdan

What is the weight for?

Demp answered 27/11, 2023 at 17:22 Comment(0)
M
1

Demp The answer is in the lerp() documentation at link posted above by Sair 😉

Monzonite answered 27/11, 2023 at 17:49 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.