So I'm doing this Tutorial Series:
We make a ball roll around in this part of the tutorial. The ball uses a box collider and in order to give the appearance that the ball is rolling around we rotate it's mesh instance which is a sphere. That's all fine and dandy and covered in the tutorial but what I'd like to do is make the balls rotation slow down in a similar fashion to how the movement speed slows down when the keypresses cease. The movement is slowed down using lerp and move_and_slide.
func _physics_process(delta):
# Handle Left/Right Movement
if Input.is_action_pressed("ui_left") and Input.is_action_pressed("ui_right"):
v3_velocity.x = 0
elif Input.is_action_pressed("ui_right"):
v3_velocity.x = -const_speed
$MeshInstance.rotate_z(deg2rad(8))
elif Input.is_action_pressed("ui_left"):
v3_velocity.x = const_speed
$MeshInstance.rotate_z(-deg2rad(8))
else:
v3_velocity.x = lerp(v3_velocity.x, 0, 0.1)
# This doesn't work, not sure how to make it work
$MeshInstance.rotate_z(lerp($MeshInstance.get_rotation_z(), 0, 0.1))
# Handle Up/Down Movement
if Input.is_action_pressed("ui_up") and Input.is_action_pressed("ui_down"):
v3_velocity.z = 0;
elif Input.is_action_pressed("ui_up"):
v3_velocity.z = const_speed
elif Input.is_action_pressed("ui_down"):
v3_velocity.z = -const_speed
else:
v3_velocity.z = lerp(v3_velocity.z, 0, 0.1)
move_and_slide(v3_velocity)