Some weird bugs

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By VivAZ

Good day!

I’m currently new to Godot and programming but I’ve been making a lot of progress however I just can’t seem to find my mistakes or solutions to these problems with my game. I want to make a Celeste type of game and hopefully when i get everything on lock down teach others how to make it. I’ve got four things I’m not able to solve after I’ve tried everything. If there is also anything else that doesn’t look right or can be done on a better way please let me know so I can improve!

The first problem is the fact that my dash is not 45 degrees when i press UP RIGHT DASH or even any other Ordinal directions. I would thought since I put the same amount of motion in the x and y direction it would move 45 degrees from the floor.

The second problem is the fact that when I push top and left at the same time and then press jump the player does not jump at all. He jumps however when I press any other two directions in the same time.

The Third problem is after the player wallgrabs the jump_count is resetted to 0 and even with this the player is still not able to double jump after wallgrab.

The last problem is not really a problem I just want to know more why it is not working if I make the #movement and direction part under the dashing function its own function the dash of the player completely changes to a short dash rather than a long one or if i change the elif to if it also change to a short dash.

Z = dash
X = Wallclimb
Spacebar = Jump
Here is my game
My game’s Repository
Here is my main code:

extends KinematicBody2D
var motion = Vector2()
var input_direction_x = 0
var input_direction_y = 0
var last_dir = 1
var dash_count = 0
var jump_count = 0
var dashing_x = false
var dashing_y = false
var dashing_xy = false
export var GRAVITY = 20
export var ACCELERATION = 50
export var DASH_ACCELERATION = 100
export var MAX_SPEED = 400
export var JUMP_HEIGHT = -650
export var MIN_JUMP = -300
const MAX_JUMP_COUNT = 1
const DASH_SPEED = 1000
const UPWARDS = Vector2(0, -1)
const DASH_TIME = 0.3
const dash_acc = 0
func _ready():
func _input(event): 
func _physics_process(delta):
func move():
    motion = move_and_slide(motion, UPWARDS)
func Jump(event):
    if jump_count < MAX_JUMP_COUNT and event.is_action_pressed("ui_spacebar"):
        motion.y =  JUMP_HEIGHT
        jump_count += 1
    if Input.is_action_just_released("ui_spacebar"):
        if motion.y < MIN_JUMP:
            motion.y = MIN_JUMP
func controls(delta):
    var UP = Input.is_action_pressed("ui_up")
    var LEFT = Input.is_action_pressed("ui_left")
    var RIGHT = Input.is_action_pressed("ui_right")
    var DOWN = Input.is_action_pressed("ui_down")
    input_direction_x = -int(LEFT) + int(RIGHT)
    input_direction_y = -int(UP) + int(DOWN)
func dashing(delta):
    if dashing_xy:
        dash_acc += delta
        if dash_acc >= DASH_TIME:
            dashing_xy = false
            motion.x = 0
            motion.y = 0
            dash_acc = 0
    if dashing_y:
        dash_acc += delta
        motion.x = 0
        if dash_acc >= DASH_TIME:
            dashing_y = false
            motion.y = 0
            dash_acc = 0
    if dashing_x:
        motion.y = 0
        dash_acc += delta
        if dash_acc >= DASH_TIME:
            dashing_x = false
            motion.x = 0
            dash_acc = 0
    #movement and direction
    elif input_direction_x == -1:
        last_dir = input_direction_x
        motion.x = max(motion.x - ACCELERATION, -MAX_SPEED)
    elif input_direction_x == 1:
        last_dir = input_direction_x
        motion.x = min(motion.x + ACCELERATION, MAX_SPEED)
    elif !input_direction_x: 
        motion.x = lerp(motion.x, 0, 0.2)
func wallgrab():
    var WALL_GRAB = Input.is_action_pressed("wallgrab")
    if WALL_GRAB and ($RayCastRight.is_colliding() or $RayCastLeft.is_colliding()):
        GRAVITY = 0
        jump_count = 0
        motion = Vector2(0,0)
        if input_direction_y:
            motion.y = input_direction_y * MAX_SPEED
        GRAVITY = 20
#Reset when on floor and prevents double dashing from ground
func onfloor():
    if is_on_floor():
        jump_count = 0
        dash_count = 0
        if Input.is_action_pressed("dash"):
            dash_count += 1
func gravity(delta):
    motion.y += GRAVITY
func dash(event):
    var UP_LEFT = Input.is_action_pressed("ui_up") and Input.is_action_pressed("ui_left")
    var UP_RIGHT = Input.is_action_pressed("ui_up") and Input.is_action_pressed("ui_right")
    var DOWN_LEFT = Input.is_action_pressed("ui_down") and Input.is_action_pressed("ui_left")
    var DOWN_RIGHT = Input.is_action_pressed("ui_down") and Input.is_action_pressed("ui_right")
        #Dash Movements
    if (event.is_action_pressed("dash") and dash_count < 1) and UP_LEFT:
        motion = Vector2(-DASH_SPEED, -DASH_SPEED)
        dash_count += 1
        dashing_xy = true
    if (event.is_action_pressed("dash") and dash_count < 1) and UP_RIGHT:
        motion = Vector2(DASH_SPEED, -DASH_SPEED)
        dash_count += 1
        dashing_xy = true
    if (event.is_action_pressed("dash") and dash_count < 1) and DOWN_LEFT:
        motion += Vector2(-DASH_SPEED, DASH_SPEED)
        dash_count += 1
        dashing_xy = true
    if (event.is_action_pressed("dash") and dash_count < 1) and DOWN_RIGHT:
        motion += Vector2(DASH_SPEED, DASH_SPEED)
        dash_count += 1
        dashing_xy = true
    if input_direction_y  &&  event.is_action_pressed("dash") && dash_count < 1:
        dash_count += 1
        motion.y = input_direction_y * DASH_SPEED
        dashing_y = true
    if event.is_action_pressed("dash") && dash_count < 1:
        dash_count += 1
        motion.x = last_dir * DASH_SPEED
        dashing_x = true    

So I found out the solution to my second problem is if I make my jump key spacebar it does not work however if i change my jump to x it does work with any directions. Is there a certain reason for this?

VivAZ | 2018-07-02 15:34