Weird glitch with jump and running

So I found this weird glitch where if after jumping you run towards a wall, you get ‘locked’ vertically and you continue running into the wall until you let go of the run button after which you drop down. The gif below illustrates the same issue. Any reason why this might be an issue?

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.InputSystem;

public class PlayerMovement : MonoBehaviour
{

    Vector2 moveInput;
    Rigidbody2D myRigidbody;
    Animator myAnimator;
    CapsuleCollider2D myCapsuleCollider;
    [SerializeField] float runSpeed = 10f;
    [SerializeField] float jumpSpeed = 5f;
 
    void Start()
    {
        myRigidbody = GetComponent<Rigidbody2D>();
        myAnimator = GetComponent<Animator>();
        myCapsuleCollider = GetComponent<CapsuleCollider2D>();
        myAnimator.SetBool("isRunning",false);
    }

    void Update()
    {
        Run();
        FlipSprite();
    }

    void OnMove(InputValue value)
    {
        moveInput = value.Get<Vector2>();
        Debug.Log(moveInput);
    }

    void OnJump(InputValue value)
    {
        if (!myCapsuleCollider.IsTouchingLayers(LayerMask.GetMask("Ground")))
        { 
            return;
        }

        if(value.isPressed)
        {
            myRigidbody.velocity += new Vector2 (0f, jumpSpeed);
            //myAnimator.SetTrigger("isJump");
            //myAnimator.ResetTrigger("isIdle"); 
        }
    }

    void Run()
    {
        Vector2 playerVelocity = new Vector2 (moveInput.x * runSpeed, myRigidbody.velocity.y);
        myRigidbody.velocity = playerVelocity;

        bool playerHasHorizontalSpeed = Mathf.Abs(myRigidbody.velocity.x) > Mathf.Epsilon;
        myAnimator.SetBool("isRunning",playerHasHorizontalSpeed);
        
    }

    void FlipSprite()
    {
        bool playerHasHorizontalSpeed = Mathf.Abs(myRigidbody.velocity.x) > Mathf.Epsilon;
        if (playerHasHorizontalSpeed)
        {
            transform.localScale = new Vector2 (Mathf.Sign(myRigidbody.velocity.x),1f);
        }
        
    }
}

movie_001

1 Like

Hi,

That looks like a bug Rick fixes in lecture “Prevent Wall Jump”. Have you already watched that lecture?

No not yet! In that case I’ll ignore it until I get to that part of the lecture. Thank you!!

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms