Below is the gdscript I slapped together to experiment with a camera gimbal idea. The idea is for the camera to smoothly interpolate 30 degrees left and right with a button press, as well as zoom in and out with its own button. Interpolation functions as it is intended with left, right and zoom however, the inner gimbal does not interpolate, but rather snaps to its new position. Everything functions but that interpolation. I have the scene set up as a standard camera gimbal.
CamGimbal(script below attached)
-> InnerGimbal
-> -> Camera
extends Spatial
var zoom = 1.2
var new_y_rotation = 0
var new_x_rotation = 0
func get_input_keyboard(delta):
# Rotate outer gimbal around y axis
if Input.is_action_just_pressed("camera_right"):
new_y_rotation += 1
if Input.is_action_just_pressed("camera_left"):
new_y_rotation += -1
if Input.is_action_just_pressed("camera_up"):
new_x_rotation += -1
if Input.is_action_just_pressed("camera_down"):
new_x_rotation += 1
if Input.is_action_just_pressed("zoom_in"):
zoom -= .5
if Input.is_action_just_pressed("zoom_out"):
zoom += .5
$InnerGimbal.rotation.x = lerp(rotation.x, new_x_rotation, 0.12)
rotation.y = lerp(rotation.y, new_y_rotation, 0.12)
func _process(delta):
print(rotation.y)
get_input_keyboard(delta)
scale = lerp(scale, Vector3.ONE * zoom, 0.05)