- Home /
Preventing player from sticking to the wall while jumping?
I'm working on a 2d platformer game for a school project. I know little about coding, here's all I have so far.
[SerializeField] private float speed;
private Rigidbody2D body;
private Animator anim;
private bool grounded;
private void Awake()
{
body = GetComponent<Rigidbody2D>();
anim = GetComponent<Animator>();
}
private void Update()
{
float horizontalInput = Input.GetAxis("Horizontal");
body.velocity = new Vector2(horizontalInput * speed, body.velocity.y);
if (horizontalInput > 0.01f)
transform.localScale = Vector3.one;
else if (horizontalInput < -0.01f)
transform.localScale = new Vector3(-1, 1, 1);
if (Input.GetKey(KeyCode.Space) && grounded)
Jump();
anim.SetBool("Running", horizontalInput != 0);
anim.SetBool("grounded", grounded);
}
private void Jump()
{
body.velocity = new Vector2(body.velocity.x, speed + 5);
grounded = false;
}
private void OnCollisionEnter2D(Collision2D collision)
{
if (collision.gameObject.tag == "Ground")
grounded = true;
}
The player can stick to a wall while jumping if you move into it. I want to fix that so the player always falls down. Does anyone know how to do that?
Answer by honor0102 · Oct 31, 2021 at 05:36 PM
simply create a physic material that has low friction then apply it on the player collider (or even for wall collider if you want more smoothness!) https://answers.unity.com/questions/794668/2d-character-controller-getting-stuck-on-walls.html
Your answer
Follow this Question
Related Questions
How to fix glitching walls? Unity5 2D topdown view 1 Answer
3d model going through walls 0 Answers
How to set a realistic wall physic 0 Answers
Camera Collision with Wall 1 Answer
Stuck Between tilemap colliders 0 Answers