Hello,
I’m trying to do a breakout game. Nothing too complicate … in theory.
I had everything seemingly working fine, until I wanted to accelerate the ball movement and noticed the contact is detected too late as you can see in the picture below.
The ball has a size of 0.2, the brick has a Y size of 0.3.
The collision is detected at Y position 0.14, so slightly above the bottom part which is at 0.15 (0.3 / 2).
At first I setup the objects as triggers.
When I noticed that problem I setup everything as colliders but the behavior is the same.
I tested the different options for the Rigidbody setup, first activating “Full Kinematic Contacts”, then switching “Collision detection” from discrete to continuous, then activating the “Interpolate” option. Same behavior.
The ball and bricks are setup the same way:
According to the doc:
Continuous: When the Collision Detection is set to Continuous, GameObjects with Rigidbody 2Ds and Collider 2Ds do not pass through each other during an update. Instead, Unity calculates the first impact point of any of the Collider 2Ds, and moves the GameObject there. Note that this takes more CPU time than Discrete.
This is clearly not what I get.
I could increase the ball hitbox or use some kind of epsilon to determine the Y collision (like 0.14 + epsilon > 0.15) but I would rather use the Unity physics engine.
To be noted that at smaller speed of the ball I do not get this problem.
In the past I remember I solved the same kind of collision issues by setting “Collision detection” to continuous, but it does not seem to work this time.
[Edit]
I setup back the objects (brick and ball) to Triggers and added an Epsilon half the size of the ball.
While it works for higher speed, if I set some huge speed values, the behavior starts to be wrong again:
at some speed the collision detection works for the bricks but not for the racket,
At a higher speed the ball goes through some of the bricks and the trigger is register at like the 3rd row,
and at even higher speed the ball goes through everything (all the bricks + the top part of the game area).
Anyway it is working well enough for high enough speeds that I need, but I wonder how you could get bullets physics in a Unity games. I suppose we can’t solely rely on the physics engine.
Thanks for reading