Okay first of all im very new to godot so please excuse my probably messy code or dumb question.
The thing is that i got a 2D KinematicBody for the player and its speed can change when different mechanics are activated, atm i have a dash and sort of a slow down effect when rightCliking to aim but the code i used for the dash overrides any speed change that isnt the one the dash makes. Any suggestions?
(the start_dash function is just triggers a timer to determine how long the dash's speed increase should go for)
extends KinematicBody2D
export (int) var defaultSpeed = 300
var speed = defaultSpeed
var velocity = Vector2()
const dashSpeed = 1000
const dashLength = 0.08
onready var dash = $Dash
export(PackedScene) var ROCK: PackedScene = preload("res://Scenes/ThrowingRock.tscn")
func read_input():
velocity = Vector2()
if Input.is_action_pressed("Up"):
velocity.y -= 1
if Input.is_action_pressed("Down"):
velocity.y += 1
if Input.is_action_pressed("Left"):
velocity.x -= 1
if Input.is_action_pressed("Right"):
velocity.x += 1
if Input.is_action_just_pressed("leftShift"):
dash.start_dash(dashLength)
var speed = dashSpeed if dash.is_dashing() else defaultSpeed
velocity = velocity.normalized() * speed
look_at(get_global_mouse_position())
if Input.is_action_just_pressed("leftClick"):
throw_rock()
print("BAM!")
if Input.is_action_just_pressed("rightClick"):
print("take aim...")
if Input.is_action_pressed("rightClick"):
speed = lerp(speed, 100, 0.15)
else:
speed = lerp(speed, defaultSpeed, 0.3)