- Home /
Edge Collider issue
Here is a video where i showcase the issue. The edges have box colliders attached to them. I tried changing the max penetration in the Physics2DSettings but it still acts weirdly... I also tried changing the "Collision Detection" property to continuous on the rigidbody component, but it still didn't work. So is there any way to fix this? I assume it has something to do with how unity collisions work :/
Answer by MelvMay · Aug 31, 2016 at 08:57 AM
First, reset the max-penetration back to its default; it's actually very bad to change it unless you know what you're doing.
Unity 2D physics (Box2D) provides rock solid detection for this kind of thing, especially continuous collision detection which you should definitately use for faster moving objects against thin colliders like edges.
The most likely reason it's happening is because you're causing an overlap with the edge by modifying the Transform component on your 'player' to either reposition it or change the angle. When you do this, you're warping it from one position/angle, instantly to another causing the overlap which the physics system cannot easily solve, especially if you're doing this continuously, stomping over what it's doing.
You should use Rigidbody2D.MovePosition & Rigidbody2D.MoveRotation to change the position and angle of the Rigidbody2D respectively.
I didn't notice that my rotation is using transform to rotate. This was the code that i was using transform.Rotate(rotationSpeed * new Vector3(0, 0, -10) * Time.deltaTime);
and this is the code that i got from the unity documentation Quaternion deltaRotation = Quaternion.Euler(rotationSpeed * Time.deltaTime); myRigidbody.$$anonymous$$oveRotation(myRigidbody.rotation * deltaRotation);
But i am getting an error on the second line: "Operator '*' cannot be applied to operands of type 'float' and 'Quaternion'.
I actually fixed it by calling the function from fixed update since * Time.deltatime didn't work, and the command is rigidbody.rotation = rigidbody.rotation + / - rotationSpeed. I set the collision detection to continuous and i reset the max penetration, it still glitches and goes through...
That's because you're missing the reason why I explained previously. Again, you cannot simply reposition or change angle of a body continuously either via the Transform component or directly on the body itself and expect collision detection to work correctly; you are fighting the physics system. The physics system expects to move the position/angle itself via the linear/angular velocity; this is what Rigidbody2D.$$anonymous$$ovePosition and Rigidbody2D.$$anonymous$$oveRotation does i.e. calculate the velocity required to move the position/rotation during the next fixed update.it still glitches and goes through...