- Home /
Wrong 2D collision detection
Hello!
When bullet speed is low, collisions detected too early ot too late (you can see it on first pic - some bullets explode before sprite actually touched box, and some - inside of box). I have tried all combinations of dynamic/kinematic\static body types for bullet and box (and continious/discrete collision detection). Unity 2019.4.21f1
Default Contact Offset: 0.01
Bullet moving code:
newShot.GetComponent<Rigidbody2D>().velocity = currentGunPoint.transform.right * 2f;
Collision detection code:
void OnTriggerEnter2D(Collider2D col)
{
if (col.gameObject.tag != "Sense")
Explode();
}
When bullets speed up (faster 4x times) all collisions detected inside of the box (pic 2).
Am i doing something wrong? Or i should change my collision mechanism? Like add small raycast to every bullet or smth?
Cant upload pics cause of parsing error, so uploaded them to google drive
First collision pic: https://drive.google.com/file/d/1h44a0Qu1N4dpBLuogkYEyPtXQWAx1ux6/view?usp=sharing Second (4x bullet speed) https://drive.google.com/file/d/1I9KAkCSTXQnHUjzao5IJX-Hp5UIOIj4s/view?usp=sharing
Your answer
Follow this Question
Related Questions
Characters Not Sliding Past Each Other 1 Answer
Can I have a single rigidbody2d that acts as both collider and trigger? 1 Answer
How to best determine which direction an OnTriggerEnter object came from? 2 Answers
Physics2dOverlapBox is detecting every custom layer 1 Answer
OnCollisionEnter2D(coll: Collision2D) function not being triggered 0 Answers