- Home /
Unity2D- Disabling a collider moving towards an object doesn't stop the collision
My game is a top down 2D game and i want my player to be able to jump over obstacles so i disable the collider everytime the player jumps.
public IEnumerator Jump()
{
float time = 0;
IsJumping = true;
Collider.enabled = false;
while (time<0.25f)
{
time += Time.deltaTime;
transform.localScale += new Vector3(Time.deltaTime*1.2f, Time.deltaTime * 1.2f);
yield return null;
}
transform.localScale = new Vector3(1.3f, 1.3f);
while (time < 0.5f)
{
time += Time.deltaTime;
transform.localScale -= new Vector3(Time.deltaTime * 1.2f, Time.deltaTime * 1.2f);
yield return null;
}
transform.localScale = new Vector3(1, 1);
Collider.enabled = true;
IsJumping = false;
}
When i disable the collider and the player is moving towards the wall it acts like it's still colliding, if the player stops, then jumps(disabling collider) and moves towards the wall it works but if the player is already moving then jumps the player gets stuck unless they stop or move the other way.
Answer by Extroia · Aug 22, 2021 at 05:00 PM
Solved it, for some reason using the new input system was doing this weird interaction, switching back to the old one solved it.
Your answer
Follow this Question
Related Questions
NavMesh and 2D top-down games 0 Answers
Moving an object after player click? 1 Answer
How can I improve 2D Jump? because it's sluggish 1 Answer
How to keep Y velocity normal? 1 Answer