#Dash currently sends player only slightly forwards horizontally but way too high vertically

1 messages · Page 1 of 1 (latest)

dusty ginkgo
#

Here is the code I am working with, as the title states the dash in the physics_process function sends the player way up vertically, I'd say about 10 times their height, while the horizontal dash makes them move 1 times their width. Trying to figure out why.

The Characterbody2d script:
(```)
extends CharacterBody2D

const SPEED = 100.0
const JUMP_VELOCITY = -150.0

const PUSHBACK = -400
const GRAVITY = 400
const WALL_GRAVITY = .8

var CAN_DASH = true
var DASH_COUNT = 1

@onready var dash := $dash

func _physics_process(delta: float) -> void:

var direction := Input.get_axis("Left", "Right")
var DASH_DIRECTION := Input.get_axis("Up","Down")
# Add the gravity.
if not is_on_floor() and !dash.DASHING:
    velocity.y += GRAVITY * delta
    if DASH_COUNT > 0:
        CAN_DASH = true
    else: CAN_DASH = false

if is_on_floor():
    CAN_DASH = true
# Handle jump.
if Input.is_action_just_pressed("Jump") and is_on_floor() and !dash.DASHING:
    velocity.y = JUMP_VELOCITY
    
if direction and !dash.DASHING:
    velocity.x = SPEED * direction
else: 
    velocity.x = move_toward(velocity.x, 0, SPEED)
    
if is_on_wall() and Input.is_action_just_pressed("Jump"):
    if Input.get_axis("Left","Right"):
        velocity.y = JUMP_VELOCITY
        velocity.x = direction * PUSHBACK

if is_on_wall() and !is_on_floor() and Input.get_axis("Left","Right"):
    velocity.y *= WALL_GRAVITY

if Input.is_action_just_pressed("Dash") and CAN_DASH:
    !dash.DASHING
    !CAN_DASH
    velocity +=  Input.get_vector("Left", "Right","Up","Down") * dash.DASH_SPEED
    dash.start_dash(dash.DASH_DURATION)
    
move_and_slide()

(```)

serene mauve
#

First thing is that these 2 lines do nothing, not sure if you where relying on them for something.

Also, could your dasg/jump action share inputs of some kind?

dusty ginkgo
#

I was using them to basically invert the current bool but okay lol

#

Ty for the info

#

Also maybe? I really don’t want to make up the jump tho I’d rather map to a button

dusty ginkgo
serene mauve
#

It is, but you are just saying "opposite of this"
It is not changing anything

dusty ginkgo
#

Righttt

serene mauve
#

I think you meant CAN_DASH = !CAN_DASH

dusty ginkgo
#

Yeah that’s what I was thinking ty

#

But uh, do you know anything about the issue of the velocity?

#

The code stored in the 2D node dash object just starts the dash timer and the variables, and the dash speed should be the same going vertically or horizontally but it’s definitely not lol

serene mauve
#

It is hard to tell tbh (i'm also a bit short on time to check :p)
Normally i'd just place a breakpoint and run trough the function one line at a time, keeping an eye on how the velocity changes.
That would at least let you know WHERE it goes wrong.

dusty ginkgo
#

Oh? Breakpoint?

#

But ty nonetheless

#

Was very helpful

dusty ginkgo
#

hey so @serene mauve I tried debugging by giving it a line that prints the velocity

#

it seems the horizontal velocity is consistent but vertical makes it return a seemingly random number and accelerates in that direction infinitely until it hits a wall

#

horizontal