Forum begins after the advertisement:


[Part 8] My slide jump not working

Home Forums Video Game Tutorial Series Creating a Metroidvania in Unity [Part 8] My slide jump not working

Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • #13819
    #13820
    Elvin Sim
    Participant
    private bool Walled()
    {
        return Physics2D.OverlapCircle(wallCheck.position, 0.2f, wallLayer);
    }
    
    void WallSlide()
    {
        if(Walled() && !Grounded() && xAxis != 0)
        {
            isWallSliding = true;
            rb.velocity = new Vector2(rb.velocity.x, Mathf.Clamp(rb.velocity.y, -wallSlidingSpeed, float.MaxValue));
        }
        else
        {
            isWallSliding = false;
        }
    }
    
    void WallJump()
    {
        if(isWallSliding)
        {
            isWallJumping = false;
            wallJumpingDirection = !pState.lookingRight ? 1 : -1;
    
            CancelInvoke(nameof(StopWallJumping));
        }
    
        if(Input.GetButtonDown("Jump") && isWallSliding)
        {
            isWallJumping = true;
            rb.velocity = new Vector2(wallJumpingDirection * wallJumpingPower.x, wallJumpingPower.y);
    
            dashed = false;
            airJumpCounter = 0;
            pState.lookingRight = !pState.lookingRight;
            transform.eulerAngles = new Vector2(transform.eulerAngles.x, 180);
            
    
            Invoke(nameof(StopWallJumping), wallJumpingDuration);
        }
    }
    
    void StopWallJumping()
    {
        isWallJumping = false;
        transform.eulerAngles = new Vector2(transform.eulerAngles.x, 0);
    }
    #13821
    Elvin Sim
    Participant
    [Header("Wall Jump Settings")]
     [SerializeField] private float wallSlidingSpeed = 2f;
     [SerializeField] private Transform wallCheck;
     [SerializeField] private LayerMask wallLayer;
     [SerializeField] private float wallJumpingDuration;
     [SerializeField] private Vector2 wallJumpingPower;
     float wallJumpingDirection;
     bool isWallSliding;
     bool isWallJumping;
    #13822
    Elvin Sim
    Participant
    void Update()
    {
        if (pState.cutscene) return;
        if (pState.alive)
        {
            GetInputs();
            ToggleMap();
            Heal();
        }
       
        UpdateJumpVariables();
        UpdateCameraYDampForPlayerFall();
        RestoreTimeScale();
    
        if (pState.dashing || pState.healing) return;
        if (pState.alive)
        {
            if (!isWallJumping)
            {
                Flip();
                Move();
                Jump();
            }
            
            WallSlide();
            WallJump();
    
            StartDash();
            Attack();
            CastSpell();
        }
        FlashWhileInvincible();
    }
    #13823
    #13824
    Elvin Sim
    Participant

    I also want to ask there is a [SerializeField] private float maxFallingSpeed in the code but in the past video I don’t see this code

    #13828
    Joseph Tang
    Moderator

    There’s a few possibilities.

    1) Your wallLayer on your PlayerController.cs and wall object’s Layer is not set.

    Check the gameobject you are using as your wall in the scene, and check that it’s layer is set to the same layer you put for the wallLayer variable on your Player.

    2) Your “Wall Check” object is not far enough from your player to reach the wall before the Player’s BoxCollider2D.

    Check the position of your Player’s BoxCollider2D and the position of your “Wall Check” object. Ensure that the object is outside the BoxCollider of your Player.

    3) Your wall jump works but your sliding isn’t affecting the your fall speed against a wall

    Your wallSlidingSpeed is, despite being set when created, not at a high enough value to have a significant change in speed.

    Someone else had also experienced a seperate bug with the working walljump, i’ve provided an improved code in it too if you want to improve the code as well.

    [part 8] walljump bugs

    #13829
    Elvin Sim
    Participant

    Thank you!!!

Viewing 8 posts - 1 through 8 (of 8 total)
  • You must be logged in to reply to this topic.

Go to Login Page →


Advertisement below: