top down 2D movement by holding into mouse to dash

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

i have been trying to figured out how to adapt from the movement tutorials about “player move to mouse” movement into some sort of " dash into mouse " that also has the gimmick where its like “the longer you hold, the further you go” kinda like a golf if that sounds right.

However, the movement mechanic just doesnt move the player in any way. is there anything that i forget to do or i didnt notice, thankyou.

extends KinematicBody2D
onready var power = 1
onready var maxpower = 100
onready var powerexcalator = 0.5
var velocity = Vector2()

var aim_direction = global_position.direction_to(get_global_mouse_position())

func _input(event):
	if event.is_action_pressed("click"):
		power = clamp(power+powerexcalator, 0, maxpower)
	elif event.is_action_released("click"):
		velocity = aim_direction*power
		power = 1
		
# warning-ignore:unused_argument
func _physics_process(delta):
	velocity = move_and_slide(velocity)
:bust_in_silhouette: Reply From: rossunger

that’s not how move_and_slide works.

I would put all your code in the _physics_process event and just check

if Input.is_action_pressed("click"):  power = clamp(power+powerexcalator, 0, maxpower)
if Input.is_action_just_released("click"): 
 velocity = aim_direction*power
 power = 1

move_and_slide()