0 votes

Hello everyone, I know I haven't been very active, but now I'm in the middle of developing a video game in godot and I have the physics of my character, it's just that they don't work the way I wanted, and it's in the part where The one that I put the wall slide does it perfectly but there is only one problem, and that is that when it reaches the floor the animation of the wall slide continues to play and I only want it to play on the wall, besides that when I want to create an attack it gets stuck and doesn't continue its animation, if someone could help me I would appreciate it, it's my own megaman x style engine if it helps someone you can use it and try it, and if you can shorten it or solve my problem I would appreciate it, I would also put it inside of the credits of my game at the end of it, without further ado, here is the script and I hope you can fix it since it is a TREMENDOUS disaster: 'v

extends KinematicBody2D

var can_intro = true
var entering = false

var vel = Vector2()
var speed = 7
var grv = 9
var jump_speed = -180
var wall_kick = 175
var wall_jump = -230

var can_wall_slide = true

var continue_running = false

const wall_slide_speed = 50
const wall_slide_gravity = 60

var puntos = 0

var can_move = false
var can_wall_jump = false

var is_wall_sliding : bool = false

var is_wall_jumping = false

var can_hurt = true

var can_attack = false
var animate = true

var countdown = false

var jumps_left = 1

func _ready():
    $Camera2D.current = false
    can_move = false
    animate = false
    can_intro = true

# warning-ignore:unused_argument
func _physics_process(delta):
    Anim_CTRL()
    if can_move == false:
        if can_intro == true && !is_on_floor():
            vel.y = 375
            if is_on_floor():
                can_intro = false
                vel.y = 0
                entering = true
        if can_intro == false && is_on_floor():
            entering = true
            if entering == true:
                vel.y = 0
                can_intro = false
        if entering == false && can_intro == false:
            can_move = true
        if can_intro == false && entering == false:
            can_move = true

    if can_move == true:
        if is_on_floor():
            can_wall_slide = false
        elif !is_on_floor():
            can_wall_slide = true

        animate = true
        if is_in_group("COIN"):
            $AudioStreamPlayer.play()
        if $AnimatedSprite.animation == "WALL_SLIDE":
            can_wall_jump = true
        else:
            can_wall_jump = false
        if is_on_floor() && Input.is_action_pressed("ui_right") or Input.is_action_pressed("ui_left") && is_on_wall():
            is_wall_sliding = false
            animate = true


        vel.y += grv
        if vel.y > 150:
            vel.y = 125


        if vel.x > 100:
            vel.x = 30
        elif vel.x < -100:
            vel.x = -30
        if Input.is_action_pressed("ui_right"):
            vel.x += speed
            $AnimatedSprite.flip_h = false
        elif Input.is_action_pressed("ui_left"):
            vel.x -= speed
            $AnimatedSprite.flip_h = true
        if Input.is_action_just_pressed("ui_left") or Input.is_action_just_pressed("ui_right"):
            continue_running = true

        if Input.is_action_just_released("ui_right"):
            vel.x = 0
        elif Input.is_action_just_released("ui_left"):
            vel.x = 0

        if is_on_floor():
            if Input.is_action_just_pressed("jump"):
                vel.y += jump_speed
                $Jump.play()
                $AudioStreamPlayer2/hat.play()
        if !is_on_floor() && !vel.y > 0:
            if Input.is_action_just_released("jump"):
                vel.y += 75
#-----------------Wall_slide--&&--wall_kick-----------#
        if can_wall_slide == true:
            if is_on_wall() && not is_on_floor():
                animate = false
                if $AnimatedSprite.flip_h == true && Input.is_action_pressed("ui_left"):
                    if Input.is_action_just_pressed("jump") && can_wall_jump == true:
                        vel.x += wall_kick
                        vel.y += wall_jump
                        animate = false
                        is_wall_jumping = true
                        $double_jump.play()
                        $AnimatedSprite.play("wall_kick")
                        $AudioStreamPlayer2/hut.play()
                if $AnimatedSprite.flip_h == false && Input.is_action_pressed("ui_right"):
                    if Input.is_action_just_pressed("jump") && can_wall_jump == true:
                        vel.x -= wall_kick
                        vel.y += wall_jump
                        animate = false
                        is_wall_jumping = true
                        $double_jump.play()
                        $AnimatedSprite.play("wall_kick")
                        $AudioStreamPlayer2/hut.play()
                    else:
                        is_wall_jumping = false
                        animate = true
                else:
                    is_wall_jumping = false
                    animate = true
            else:
                is_wall_jumping = false
                animate = true
            if is_on_wall() and not is_on_floor() and vel.y > 0:
                if Input.is_action_pressed("ui_right") or Input.is_action_pressed("ui_left"):
                    is_wall_sliding = true
                else:
                    is_wall_sliding = false

            else:
                is_wall_sliding = false

#----------------WALL_SLIDE----------------------#
        if can_wall_slide == true:
            if is_wall_sliding == true:
                vel.y += wall_slide_gravity
                vel.y = min(vel.y, wall_slide_speed)
                animate = false
                $Particles2D.emitting = true
                can_attack = false
            if is_wall_sliding == false:
                animate = true
                $Particles2D.emitting = false


            if $AnimatedSprite.flip_h:
                $Particles2D.position.x = -8
            elif not $AnimatedSprite.flip_h:
                $Particles2D.position.x = 8 
        vel = move_and_slide(vel, Vector2.UP)
    vel = move_and_slide(vel, Vector2.UP)


func Anim_CTRL():
    if can_intro == true:
        if !is_on_floor():
            $AnimatedSprite.play("intro_light")
        if is_on_floor() && vel.y == 0:
            can_intro = false
    if entering == true && can_intro == false && is_on_floor():
        $AnimatedSprite.play("intro")
    if animate == true:
        if is_on_floor():
            if continue_running == true:
                if vel.x > 0:
                    $AnimatedSprite.play("prerun")
                if vel.x < 0:
                    $AnimatedSprite.play("prerun")
            if vel.x > 41:
                $AnimatedSprite.play("run")
                continue_running = false
            if vel.x < -41:
                $AnimatedSprite.play("run")
                continue_running = false
            if vel.x == 0:
                $AnimatedSprite.play("idle")
        if not is_on_floor():
            if vel.y > 0:
                $AnimatedSprite.play("fall")
            if vel.y < 0:
                $AnimatedSprite.play("jump")
    if can_attack == true && is_on_floor():
        $AnimatedSprite.play("attack")
        animate = false
    if can_attack == true && !is_on_floor():
        $AnimatedSprite.play("attack_air")
        animate = false
    if is_wall_sliding == true:
        $AnimatedSprite.play("WALL_SLIDE")
    if is_wall_jumping == true:
        $AnimatedSprite.play("wall_kick")
        animate = false


func hurt_ctrl():
    if can_hurt == true:
        if is_in_group("MOB"):
            $Camera2D/Control/lifevar/VBoxContainer/TextureProgress.value -= 1
            $Timer.start()
    if countdown == true:
        can_hurt = false



func _on_AnimatedSprite_animation_finished():
    if $AnimatedSprite.animation == "attack":
        animate = true
        can_attack = false
    if $AnimatedSprite.animation == "attack_air":
        can_attack = false
        animate = true
    if $AnimatedSprite.animation == "wall_kick":
        is_wall_jumping = false
        animate = true
    if $AnimatedSprite.animation == "intro":
        can_intro = false
        entering = false
        can_move = true
        animate = true
        $Camera2D.current = true



func _on_Timer_timeout():
    countdown = false


func _on_AnimatedSprite_frame_changed():
    if $AnimatedSprite.animation == "intro":
        if $AnimatedSprite.frame == 10:
            $AudioStreamPlayer2.play()
            $AudioStreamPlayer2/hit.play()
Godot version Godot - v3.4.3
in Engine by (39 points)

1 Answer

0 votes

if is_on_floor() is true, then is_on_wall() will be false. you would need to do something like this:

if $AnimatedSprite.animation == "WALL_SLIDE":
     can_wall_jump = true
else:
     can_wall_jump = false
if is_on_floor():
     is_wall_sliding = false
     animate = true
by (30 points)

ehhh... Sorry but, this is exactly what i tried, and it doesn't solve my problem, but thanks for it

If you want, you can take the code and use it in a node and try to solve it.

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.