Hi. I want to make the control in the scrolling game concurrently by keyboard and mouse (click and move). But the mouse control don`t work properly. The character move to the edges (left-right) of the screen, even the mouse clicked in the same position. And don't move smoothly. Character appears in the edge of the screen. Also I need that move only by X axis. Here the code (mouse-and-click part):
func _input(event):
if event is InputEventMouseButton:
if event.is_action_pressed("LeftClick"):
var target_x = get_local_mouse_position().x
move_to_x(target_x)
func move_to_x(target_x):
var direction = target_x
if direction:
velocity.x = direction * SPEED
else:
velocity.x = move_toward(velocity.x, 0, SPEED)
move_and_slide()
'''