0 votes

I got really, really close to what I wanted.
There's only 1 issue with this code (besides the fact (it is a mess),
if the player hits the ground while holding the Dash Button, the character will dash and that's just not good.

func _physics_process(delta):
var move_dir = 0
var dash = 1
var grounded = is_on_floor()
Normal Run
if Input.is_action_pressed("ui_right"):
    move_dir += 1
if Input.is_action_pressed("ui_left"):
    move_dir -= 1
Dash movement
if grounded and Input.is_action_pressed("Dash"):
    print (timedash)
    timedash += delta
if is_on_wall():
    timedash = 0
    dash_impulse = 1
if timedash == 0 or timedash > 0.6:
    dash = 1
if timedash > 0 and timedash < 0.6 and grounded:
    dash = 2.333333333333333
if Input.is_action_just_released("Dash"):
    timedash = 0
if grounded:
    dash_impulse = 1
if not grounded and timedash > 0:
    dash_impulse = 2.333333333333333
GENERAL SPEED CODE
move_and_slide(Vector2(move_dir * MOVE_SPEED * dash * dash_impulse, y_velocity), Vector2(0,-1))
Godot version 3.2.3
in Engine by (14 points)
edited by

It's not clear what you are trying to achieve.

It seems like you are using 2 variable (dash and dash_impulse) which are basically the same, and multiply them together to calculate the final value of the dash speed.
it's a little twisted (i mean, you could have done the same with a single variable), but it could work. However your code is quite a mess of if, you are probabling just confusing yourself on what values to assign in each situation.

Also, the issue could come from the the is_on_floor() and is_on_wall() function, as it updates only after move_and_slide() is called. Try printing grounded on each frame and check if the results are as you expect.

The goal: to make the character dash if they press and hold the dash button while on the ground

the issue: if the character is holding the dash button while jumping, he'll dash as soon as he lands

Note:
the dash_impulse is to maintain momentum when jumping during a dash. The momentum only ends when the character lands, as intended.

well, of course it will dash as soon as it touch land, this is what you told it to do with

func _process(delta):
    if grounded and Input.is_action_pressed("Dash"):
        timedash += delta

since this piece of code is inside the _process() function, it will check for this condition on everyframe: if the player start holding dash while on air, when the character touch the ground, the condition became true and the dashing begins.

if you want the character to start dashing only if the player press Dash when on ground, you should use the func _input(event), that fire only when an input is received (or change the way your code execute the dashing alltogether)

Please log in or register to answer this question.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.

Categories