- Edited
So I'm currently trying to implement a dash on my Player character(KinematicBody2D) that, when they collide with a wall or floor, they immediately bounce right off into the opposite direction. Think of it like how the dash works for Sparkster on the SNES. I manage to implement a dash well enough but I can't seem to make it ricochet at all; any wall halts all momentum entirely until the dash state finishes. Is there anything I'm doing wrong and is there a way to implement this? Here's the script for the dash:
func _ready():
dash_timer.connect("timeout", self, "dash_timer_timeout")
pass
func dash_timer_timeout():
is_dashing = false
func get_direction_from_input():
var move_dir = Vector2()
move_dir.x = -Input.get_action_strength("ui_left") + Input.get_action_strength("ui_right")
move_dir.y = Input.get_action_strength("ui_down") - Input.get_action_strength("ui_up")
move_dir = move_dir.clamped(1)
if (move_dir == Vector2(0,0)):
if(ani.flip_h):
move_dir.x = -1
else:
move_dir.x = 1
return move_dir * dash_speed
func handle_dash(var delta):
if(Input.is_action_just_pressed("dash") and can_dash):
is_dashing = true
can_dash = true
dash_direction = get_direction_from_input()
dash_timer.start(dash_length)
if(is_dashing):
if(is_on_floor()):
is_dashing = true
if(is_on_wall()):
var collision = move_and_collide(motion * delta)
if collision:
motion = motion.bounce(collision.normal)
is_dashing = true
pass