I am in the middle of learning how to create basic platformers and have recently learnt how to create character controllers. I have encountered a weird bug when doing so, however, that puzzles me and I have no idea how to fix it. When my character is in a free fall and encounters a wall on the left or on the right, if I hold the right or left arrow keys, the character can stick to the wall and stop falling. As soon as I release these keys, it stops sticking and continues falling. What could be the reason for that? Does that have something to with scripting or colliders?
Maybe you're setting the velocity directly which stomps over the velocity changes that gravity applies?
Hi @Mails_PR You didn't quite explain how you move your object (physics system or just moving transform manually?). So I'm just guessing. It sounds just like you are using physics system to move your player. When you apply force sideways along x-axis, your Rigidbody will push against wall, and if that wall collider has friction it will stick to it like in reality if you would push some block against wall with your hand, it wouldn't fall down. So either stop adding force if touching a wall or make the wall have no or little friction.
Hello, MelvMay! Thank you for your response. I do set the velocity in FixedUpdate the following piece of code. Code (CSharp): void FixedUpdate () { if (alive && !stageComplete) { grounded = Physics2D.OverlapCircle(groundCheck.position, groundRadius, whatIsGround); anim.SetBool("Ground", grounded); anim.SetBool("Alive", alive); anim.SetFloat ("vSpeed", rb.velocity.y); float move = Input.GetAxis ("Horizontal"); anim.SetFloat("Speed", Mathf.Abs(move)); rb.velocity = new Vector2(move * maxSpeed, rb.velocity.y); //GetComponent<Rigidbody2D>(). if (move > 0 && !facingRight) { Flip(); } else if (move < 0 && facingRight) { Flip(); } } } It seems though that the problem was connected to friction since when I applied the method used in the video above, the character stopped sticking. Hello, eses! Thank you for your kind response. I am not using force but Input.GetAxis. I could attach the full script, if that would be of any help, since I really want to know the exact explanation of the problem. As said above, however, the video helped to solve the problem for now by decreasing friction to 0. Thanks for the video! It really helped
@Mails_PR "Hello, eses! Thank you for your kind response. I am not using force but Input.GetAxis." ..."It seems though that the problem was connected to friction since when I applied the method used in the video above, the character stopped sticking." ...well not sure about that video @cscox2191 posted but I already mentioned it mostly has to do with friction/physics movement (GetAxis is just input so it's irrelevant here). This is what I said: "When you apply force sideways along x-axis, your Rigidbody will push against wall, and if that wall collider has friction it will stick to it like in reality if you would push some block against wall with your hand, it wouldn't fall down. So either stop adding force if touching a wall or make the wall have no or little friction." So I'm not sure what part of my short answer you did read