#Smoother non-physics based movement

1 messages · Page 1 of 1 (latest)

gritty kettle
#

So in my game I have a camera system set up and I am wondering how I could make the zooming in and out smoother. Currently I am just changing the position of the camera every time the scroll wheel is used however I don't like the choppy movement. Does anyone know a way to make it smoother? Here is the way I handle the zooming right now:
func _input(event: InputEvent) -> void:
if Input.is_action_just_pressed("Scroll up"):
camera.position.z = camera.position.z - 0.1
if Input.is_action_just_pressed("Scroll down"):
camera.position.z = camera.position.z + 0.1

balmy nacelle
#

Use linear interpolation aka lerp or lerpf, make weight a float between 0.0 and 1.0 based on what feels the best (it's essentially the snappiness):

if Input.is_action_just_pressed("Scroll up"): camera.position.z = lerpf(camera.position.z, camera.position.z - 0.1, weight) if Input.is_action_just_pressed("Scroll down"): camera.position.z = lerpf(camera.position.z, camera.position.z - 0.1, weight)