This site is currently in read-only mode during migration to a new platform.
You cannot post questions, answers or comments, as they would be lost during the migration otherwise.
+1 vote

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 (18 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)

2 Answers

0 votes

Hi, Davi! Could you share your complete code? I'm trying for 3 days to make a dash+jump, but I just can't find any tutorial, much less achieve it alone. Please help!

by (14 points)

Look at my answer may it will help you

0 votes

Make a timer for dash by adding a timer and repeat the same code but edit it
func process(delta):
if grounded and Input.is
action_pressed("Dash"):
timedash += delta

func process(delta):
if !is
onfloor and Input.isaction_pressed("Dash"):
gravity = 0
timer.start()
timedash += delta

by (59 points)
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 Frequently asked questions and 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 [email protected] with your username.