- Home /
My player goes straight through my colider
So I'm making a 2D pizza delivering game and it has been going smoothly so far but I have run into my first issue. I'm using rigidbody2D. velocity controls so I get a continuously moving effect. But when I go over one of my buildings that has a box colider2d attached to it but my player just goes straight through the building without anything happening. This is my movement script. private void FixedUpdate() { //Player Movement if (Input.GetKeyDown(KeyCode.W) || Input.GetKeyDown(KeyCode.UpArrow)) { rb.velocity = new Vector2(0, speed); spriteRenderer.sprite = carUp; } if (Input.GetKeyDown(KeyCode.S) || Input.GetKeyDown(KeyCode.DownArrow)) { rb.velocity = new Vector2(0, -speed); spriteRenderer.sprite = carDown; } if (Input.GetKeyDown(KeyCode.D) || Input.GetKeyDown(KeyCode.RightArrow)) { rb.velocity = new Vector2(speed, 0); spriteRenderer.sprite = carRight; } if (Input.GetKeyDown(KeyCode.A) || Input.GetKeyDown(KeyCode.LeftArrow)) { rb.velocity = new Vector2(-speed, 0); spriteRenderer.sprite = carLeft; } if (Input.GetKeyDown(KeyCode.Space)) { rb.velocity = new Vector2(0, 0); spriteRenderer.sprite = carUp; } }
I don't know any way of fixing this so any help would be very much apretiated. :)
Answer by rufopufo · Aug 06, 2019 at 12:25 PM
Hi there,
In order to make a collision work, both objects must have a collider2d attached to them. And at least one of them needs a rigidbody. So, make sure, your player has got its collider2d attached too.
If this is not the case, try to change your rigidbody collision detection to Continious instead of Discrete. But your problem does not sound as it this last solution would make it work.
Hope it helped.
Answer by mlnczk · Aug 06, 2019 at 12:34 PM
As said by @rufopufo make sure both objects have Collider2d attached to them, one of them ( player ) should have rigidbody2d and also check if in Collider2d components there is unchecked box called "Is Trigger". If its checked then uncheck it. If your game is really fast pased consider changing rigidbody's collision detection to Continious or Continous Dynamic and Interpolate to Interpolate
Answer by G0DF4THER · Aug 06, 2019 at 10:29 PM
I definitely know that both my objects have a box collider 2d and changing the collision detection to continuous did nothing as well as changing interplate to interplate. :/ Thanks for your help though.
Your answer
Follow this Question
Related Questions
2D Colliders aren't actually touching but they're behaving like they do? 0 Answers
Rigidbody2D adding force vs modifying velocity for character jump 1 Answer
Convert current rigidbody velocity to transform.forward 0 Answers
Stopped Rigidbody2D still applying motion to carried objects? 0 Answers
boxcollider fixed bounds 1 Answer