I've coded a dash for my 2d platformer, and as far as I can see, the code is right. The dash is kind of working too, but it doesn't work if I've pressed any other key. So, if I press any other key, it doesn't work, which is not desirable.
I'd be most grateful if any of you guys would be so kind to help me out. I want to know what the problem is with the dash. Thanks in advance!!
The code is as follows:
const SPEED = 300.0
const JUMP_VELOCITY = -400.0
Get the gravity from the project settings to be synced with RigidBody nodes.
var gravity = 500
var isjumpcancelled = Input.isactionjustreleased("uiaccept") and velocity.y < 0.0
var isfalling = velocity.y > 0.0
var doublejump = Input.isactionjustpressed("uiaccept") and isfalling
var maxjump = 2
var canDash = true
var dashing = false
var dashDirection = Vector2.ZERO
canDash = true
if Input.is_action_just_pressed("Dash") and canDash:
velocity = dashDirection.normalized() * 3000
canDash = false
dashing = true
dashing = false
# Add the gravity.
if not isonfloor():
velocity.y += gravity * delta
max_jump = 0
dashDirection = Vector2(1,0)
dashDirection = Vector2(-1,0)
# Handle Jump.
if Input.is_action_just_pressed("Jump") and is_on_floor():
velocity.y = JUMP_VELOCITY
max_jump += 1
const double_jump_velocity = -600
if not is_on_floor() and max_jump < 2:
velocity.y += double_jump_velocity
max_jump += 1
velocity.y = 0.0
# Get the input direction and handle the movement/deceleration.
# As good practice, you should replace UI actions with custom gameplay actions.
var direction = Input.get_axis("Left", "Right")
velocity.x = direction * SPEED
velocity.x = move_toward(velocity.x, 0, SPEED)