Godot Version
4.4
Question
Hi guys. I’m trying to interpolate this line:
HEAD.rotation_degrees.y -= mouseInput.x * mouse_sensitivity
using lerp:
HEAD.rotation_degrees.y -= lerp(HEAD.rotation_degrees.y, mouseInput.x * mouse_sensitivity, cameraAcceleration * delta)
It moves smoothly, but as soon as I stop moving the mouse, the camera returns into its original position. Could someone help me, please? Thank you so much.
I could be wrong, but I don’t think you’re supposed to subtract the result you get back from lerp
at all. Try to simply SET the value instead of subtracting it.
I’m subtracting it, because otherwise the camera would rotate at the opposite direction than the mouse movement.
Then your lerp should target -mouseInput.x * mouse_sensitivity
, but I think this isn’t what you want either.
Lerp takes the first and second argument and returns a value between the two, based on a percentage supplied by the third argument.
lerp(0, 100, 0.25) == 25
lerp(50, 100, 0.5) == 75
This is often miss-used to smooth movements by supplying the current position (your case rotation) for the first and a target for the second. The third argument only has to be a number lower than 1 and greater than 0 to produce a smooth, but frame-dependant result, multiplying by delta
actually makes this frame-dependency significantly worse.
If you want to continue working with lerp
you need to define a target rotation much like you applied the initial rotation, then use that as the second argument.
var target_rotation: float = 0.0 # in class body
# in input/process function
target_rotation -= mouseInput.x * mouse_sensitivity
HEAD.rotation_degrees.y = lerp(HEAD.rotation_degrees.y, target_rotation, 0.1)
2 Likes
Thank you, but the first row
target_rotation -= HEAD.rotation_degrees.y -= mouseInput.x * mouse_sensitivity
gives me “Assignment is not allowed inside an expression.” error. Unfortunately, I’m rewriting a player script/plugin, which involves much more I’m able to handle :-/
Sorry, must’ve missed that in the copy-paste, edited the fix.
1 Like
Thank you so much. Now I’m going to analyse, what did you do 