Forum begins after the advertisement:


[part 8] walljump bugs

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #13780
    Anuk Thotawatta
    Participant
    Helpful?
    Up
    0
    ::

    When i walljump on a wall thats on the right side of the room mi character flips and can no longer walljump because the wallcheck is flipped. and when i wall jump on the left wall the character doesnt jump sideways like in hollow knight.

    View post on imgur.com

    #13808
    Joseph Tang
    Moderator
    Helpful?
    Up
    0
    ::

    I’ve encountered this problem before and here’s an updated code with an explanation to fix this bug.
    In your PlayerController.cs

    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);
    
                if((pState.lookingRight && transform.eulerAngles.y == 0) || (!pState.lookingRight && transform.eulerAngles.y != 0))
                {
                    pState.lookingRight = !pState.lookingRight;
                    int _yRotation = pState.lookingRight ? 0 : 180;
    
                    transform.eulerAngles = new Vector2(transform.eulerAngles.x, _yRotation);
                }
    
                Invoke(nameof(StopWallJumping), wallJumpingDuration);
            }
        }
    
        void StopWallJumping()
        {
            isWallJumping = false;
            transform.eulerAngles = new Vector2(transform.eulerAngles.x, 0);
        }

    When using int _yRotation = pState.lookingRight ? 0 : 180; in WallJump(), it sets the eulerAngles.y to either [0] or [180], depending on the Player’s lookingRight bool. The idea is to have the player bounce off the wall and face away from the wall when they do so. The issue with this code is that eulerAngles aren’t affected by normal forms of rotation, like movement keys in game or the Transform Rotation in the inspector, as can be seen in here: https://docs.unity3d.com/ScriptReference/Transform-eulerAngles.html#:~:text=eulerAngles%20represents%20rotation%20in%20world,localEulerAngles.

    Rather, they have to be reset by code back to a [0] value / normal to have your Player matching up correctly with your intended actions. Thus, we reset the eulerAngles.y to 0 when we write the StopWallJumping() code, where the player bounces away from the wall and stays that way for the set wallJumpingDuration before being free to move.
    Understanding how Euler Angles work, we can remove the differentiated pState.lookingRight code from WallJump() as they do not affect the eulerAngles as intended.
    Thus, allowing both directions of wall jumping to bounce off the wall.

    #13811
    Anuk Thotawatta
    Participant
    Helpful?
    Up
    0
    ::

    this worked. Thanks alot

    #14179
    Anuk Thotawatta
    Participant
    Helpful?
    Up
    0
    ::

    recently had this new bug. when i hit a wall right after wall jumping the sprite faces backwards.

    View post on imgur.com

    As you can see i accidently hit that platform on the side and my character turns the opposite direction until i restart the game.

    #14180
    Joseph Tang
    Moderator
    Helpful?
    Up
    0
    ::

    It’s probably cause you transferred from Walljumping to Wallsliding too fast. What you can do is copy the eulerangle code in the stopwalljumping method, and paste it under the if wallsliding function.

    #14202
    Anuk Thotawatta
    Participant
    Helpful?
    Up
    0
    ::

    it worked. thanks

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

Go to Login Page →


Advertisement below: