#how to add a dash in a 3d game

1 messages · Page 1 of 1 (latest)

marsh lake
#

There's quite a few ways to do it, so it depends on the type of dash you're using. If it's a one-shot fixed burst of speed you could do the following:

var dashDistance: float = 100.0
var isDash: bool = false
var dashCooldown: float = 0.0
var is_facing_right: bool =  true

if Input.is_key_just_pressed( "Dash" ):
    if dashCooldown <= 0.0:
        isDash = true
        dashCooldown = 0.5

if Input.is_key_pressed( "ui_right" ):
    is_facing_right = true
    velocity.x += RUN_SPEED

if Input.is_key_pressed("ui_left"):
    is_facing_right = false
    velocity.x -= RUN_SPEED

# add other movement code

if isDash:
    if is_facing_right:
        velocity.x += dashDistance
    else:
        velocity.x -= dashDistance
    dashCooldown -= delta
    if dashCooldown <= 0.0:
        isDash = false
move_and_slide()```
west wagon
#

not sure why, but i just fly right

#

if i hold a right when running the sceen i can move around freely until i press dash. then i go flying, right

west wagon
exotic valve
#

Lower the duration/speed.

marsh lake
#

In the 'other movement code' you'd probably want to add gravity among other things. Positive Y is downwards. Negative Y is upwards. So, velocity.y += gravity_amount for example.