The input function gets called very rapidly so it would be best to set a velocity variable in the input function and move the character in the physics process. physics process runs at the games framerate while the process function runs as fast as possible.
This will move your character when the mouse is moving but it isn't tied to your mouse speed
var velocity = Vector2()
const speed = 20
var previous_y_direction = -1 #up = -1, down = +1
func _input(event):
if event is InputEventMouseMotion:
if event.relative.y > 0:
velocity.y += speed
if previous_y_direction == -1:
previous_y_direction = 1
_play(previous_y_direction)
elif event.relative.y < 0:
velocity.y -= speed
if previous_y_direction == 1:
previous_y_direction = -1
_play(previous_y_direction)
func _physics_process(delta):
move_and_slide(velocity) # move your character
velocity.y *= 0.8 #Inertia
This will make the character match your mouse speed but it's location is detached
var velocity = Vector2(0.0, 0.0)
var previous_y_direction = -1 #up = -1, down = +1
func _input(event):
if event is InputEventMouseMotion:
velocity.y += event.relative.y * Engine.get_iterations_per_second()
if event.relative.y > 0:
if previous_y_direction == -1:
previous_y_direction = 1
_play(previous_y_direction)
elif event.relative.y < 0:
if previous_y_direction == 1:
previous_y_direction = -1
_play(previous_y_direction)
func _physics_process(delta):
move_and_slide(velocity) # move your character
velocity.y = 0 #reset velocity