How can i make a simple grappling hook using the players velocity?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Oranos

here is my code. i took it from this tutorial. https://www.youtube.com/watch?v=jf_Hz0diI8Y

extends KinematicBody

export var speed = 15
export var accel = 5
export var gravity = 40
export var jump = 15
export var dash = 10
export var boost = 30
export var sensesivity = 0.2
export var min_angle = -89
export var max_angle = 90
export var dash_cd = 1
export var boost_cd = 3

onready var head = $head
onready var dash_cooldown = $dash_cooldown
onready var boost_cooldown = $boost_cooldown
onready var raycast = $head/RayCast

var look_rot = Vector3.ZERO
var move_dir = Vector3.ZERO
var velocity = Vector3.ZERO

func _ready():
Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED)

func _physics_process(delta):
head.rotation_degrees.x = look_rot.x
rotation_degrees.y = look_rot.y

var space_state = get_world().direct_space_state

if not is_on_floor():
	velocity.y -= gravity * delta
elif Input.is_action_just_pressed("jump"):
	velocity.y = jump

move_dir = Vector3(
	Input.get_action_strength("right") - Input.get_action_strength("left"),
	0,
	Input.get_action_strength("backward") - Input.get_action_strength("forward")
).normalized().rotated(Vector3.UP, rotation.y)

velocity.x = lerp(velocity.x, move_dir.x * speed, accel * delta)
velocity.z = lerp(velocity.z, move_dir.z * speed, accel * delta)

if Input.is_action_just_pressed("dash") and dash_cooldown.is_stopped():
	dash_cooldown.start(dash_cd)
	velocity.z = velocity.z * dash
	velocity.x = velocity.x * dash

if Input.is_action_just_pressed("boost") and boost_cooldown.is_stopped():
	boost_cooldown.start(boost_cd)
	velocity.y = boost
velocity = move_and_slide(velocity, Vector3.UP)

func _input(event):
if event is InputEventMouseMotion:
	look_rot.y -= (event.relative.x * sensesivity)
	look_rot.x -= (event.relative.y * sensesivity)
	look_rot.x = clamp(look_rot.x, min_angle, max_angle)
	
func _process(delta):
if Input.is_action_just_pressed("left_click") and raycast.is_colliding():
	print("hit")