- Home /
Two Ball Collision Reflection Problem
hi,
My problem is bounce reflection. I tried to explain my problem with pictures.
Green Line : Ball direction Red Line : Collision.contact.normal. Cyan Line : Reflected direction
1) Everything is okey at this picture. Reflection is perfect.
2) Wrong! Left ball direction is up (2x Speed) Right ball direction is up(1x speed). Second ball is going to wrong direction, when first ball touched to it
void OnCollisionEnter2D(Collision2D collision)
{
ContactPoint2D contact = collision.contacts[0];
var reflek = (Vector2)Vector3.Reflect(this.Way,contact.normal);
this.Way = reflek
}
Can't you just let the physics engine handle it? Why are you using a script?
Answer by KayelGee · Jun 19, 2015 at 09:43 AM
There are a two questions I have: How big are your balls and how fast are they going? Also another small question why aren't you letting the physics engine do it for you?
I'm taking a guess here because your information is pretty vague. Your balls are moving faster than the size of their collider per frame. This can cause weird effects like object passing through each other. Try reducing the speed and see if that fixes your problems.
If that fixes your problems, but you still want to keep the speed, then you'll have to manually to collision detection through raycasts etc. This can be hard with multiple moving objects at high speeds.