Related to: https://godotengine.org/qa/86271/how-can-i-make-the-player-move-by-swing
I made the swing mechanic myself but my problem now it's that i can't go backwards passing the viewport rect of 1920x1080 pixels:
https://imgur.com/a/V977eIb

This is my code:
extends RigidBody2D
const MAX_DISTANCE = 150
export(int) var elastic_factor = 3
var launch_force := Vector2()
onready var rest = $RestPosition
func _on_touch_pressed(_event: InputEventScreenTouch):
pass
func _on_touch_drag(event: InputEventScreenDrag):
mode = RigidBody2D.MODE_KINEMATIC
launch_force = (rest.global_position - event.position).clamped(MAX_DISTANCE)
func _on_touch_released(_event: InputEventScreenTouch):
mode = RigidBody2D.MODE_RIGID
apply_central_impulse(launch_force * elastic_factor)
launch_force = Vector2()
func _unhandled_input(event):
if event is InputEventScreenTouch:
if event.pressed:
_on_touch_pressed(event)
get_tree().set_input_as_handled()
else:
_on_touch_released(event)
get_tree().set_input_as_handled()
if event is InputEventScreenDrag:
_on_touch_drag(event)
get_tree().set_input_as_handled()