My issue is the dash is not dashing. I'm new to Godot and I wrote all of this in a day, and the last thing I need for basic movement mechanics is this dash.
Movement code:
extends CharacterBody3D
#variables to be exported and displayed on the player game object
@export var player_speed = 12.0
@export var fall_acceleration = 60
@export var jump_height = 100
@export var jump_velocity = 20
@export var dash_velocity = 20
@onready var jumpcd_time = $JumpCd_Timer
@onready var dash_time = $DashTimer
var target_velocity = Vector3.ZERO
var jumpCD_On = false
var jump_amount = 0
var can_jumpDash = false
func jump():
# Edit the argument to how many seconds you want the times to be
jumpcd_time.set_wait_time(3)#seconds
# Setting one_shot to true so the timers can stop when it hits 0
jumpcd_time.one_shot = true
if jumpcd_time.time_left == 0:
jumpCD_On = false
if is_on_floor() and jumpCD_On == false and Input.is_action_just_pressed("jump"):
can_jumpDash = true
target_velocity.y = jump_velocity
jumpcd_time.start()
jumpCD_On = true
elif not is_on_floor() and can_jumpDash == true and Input.is_action_just_pressed("jump"):
double_jump_air_dash()
can_jumpDash = false
if jumpcd_time.is_stopped() == true:
jumpCD_On = false
func double_jump_air_dash():
if Input.is_action_pressed("move_forward"):
print("forward dash")
elif Input.is_action_pressed("move_backword"):
print("backword dash")
elif Input.is_action_pressed("move_left"):
print("left dash")
elif Input.is_action_pressed("move_right"):
print("right dash")
# TODO: Get the movement for dash
else:
target_velocity.y = jump_velocity
print("double jump")
func normalize_speed(direction):
if direction != Vector3.ZERO:
direction = direction.normalized()
"""Basis is the transfom matrix (x xy xz xw)
(xy y yz yw)
(xz yz z zw)
(xw yw zw w)"""
$PlayerDirection.basis = Basis.looking_at(direction)
func _physics_process(delta):
var direction = Vector3.ZERO
# Gather user input detection
if Input.is_action_pressed("move_forward"):
direction.x += 1
if Input.is_action_pressed("move_backword"):
direction.x -= 1
if Input.is_action_pressed("move_left"):
direction.z -= 1
if Input.is_action_pressed("move_right"):
direction.z += 1
jump()
normalize_speed(direction)
# Ground velocity for directional movement + jump movement
target_velocity.x = direction.x * player_speed
target_velocity.z = direction.z * player_speed
if not is_on_floor():
target_velocity.y = target_velocity.y - (fall_acceleration * delta)
velocity = target_velocity
move_and_slide()
I tried implementing a similar thing with the double jump which either didn't work logically or didn't work because I messed up with something.