0
\$\begingroup\$

Here's the problem: I'm writing arkanoid-like game in Unity 5.3. I'm using 3d physics and simply ignoring z-axis in computations. No gravity, 0 drag and velocity reset every bounce by script. My ball has sphere collider and rigidbody with Continous dynamic collision detection on it, and bricks have box colliders with continous detection. They are set like tiles, one by one, without gaps.

The problem occurs when ball collides with two bricks at once, which effects with wrong bounce angle. Smaller sphere collider makes this situation occure less often, but causes ball to ignore collisions sometimes and phase through a single bricks.

I know the probable reason for this bug, i think collision with two objects affects ball physics twice. The question is: how to avoid it?

\$\endgroup\$
  • \$\begingroup\$ I've already tried box collider and removing mentioned script, but no success there. Currently i'm experimenting wiith 2d collisions. \$\endgroup\$ – dargemir Apr 3 '16 at 8:52
1
\$\begingroup\$

When you have a bunch of adjacent box-colliders and expect that they behave like a continuous wall, then unfortunately they won't. As of version 5.3.4, this is an edge-case the Unity physics engine does not handle correctly.

When a rigidbody collides with the edge between two box-colliders, Unity will register it as a collision with the edge of one collider and give you a bounce-angle which you would not expect.

How could you work around this problem?

Either you ditch the Rigidbody on the ball, turn all the colliders into trigger-colliders, and implement the ball-physics yourself. If you want to make an authentic Arcanoid clone, all the more complex nuances of the physics engine would be switched off anyway and all that's left to do is moving the ball by a constant velocity vector and changing that velocity vector on collisions.

If you want to use the Unity physics engine (maybe adding some more detailed physics might give an interesting new spin on the old Arcanoid concept), then you will have to work around that quirk in the physics engine by building your own colliders. When you have two or more adjacent blocks, you will need to merge them into one object with one collider. That would likely be a MeshCollider (when you use 3d physics) or a PolygonCollider2D (when you use 2d physics). You will have to generate the Mesh / Path yourself using a script. Also, you will have to write an own script to check which blocks are affected when the ball collides with the collider.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.