Collision problem ... now in Unity5

Hello guys !

I have been around for some time but now I have a chance to begin working with unity.
And now things are beginning harder than in tutorials :smile:

I am trying to solve a collision problem which is probably a classic one, trying to do the minimum of work 8) (I chose unity for that :p).
I have balls in an empty cube rotating and the problem is that balls are passing through the cube after a while.

I have read some infos on this problem, and it seems it is because the ball collider is passing through my cube face collider before physics is able to see it. The problem is probably occuring when a ball is near a wall and has time to pass the collider before next physic iteration.

How will you address this problem ?

I have attach a sample project.

Cheers,
Cedric

1598474–96270–$SampleCollision.zip (180 KB)

Try to up the solver iterations count in your project’s physics settings and see if that helps. Here are the docs.

So I just tested out this old sample to check how things where doing in Unity5 … on Unity blog, they say that PhysX 3.3 is so awesome that you just activate CCD and it works … not after upgrading the project here … or is there something more to do to upgrade my old project and have collision working without adding tricks ?!

You explained it yourself:
“The problem is probably occuring when a ball is near a wall and has time to pass the collider before next physic iteration”

I’m guessing that “solver iterations” is the ticks of the physics engine and then it isn’t a trick. You are simply increasing the update rate, meaning that collision checks is happening more often, the balls do get the time to travel so far before next the next collision check is done.

Other ways to solve this includes but isn’t limited to clamping the balls speed so that they can never travel at a speed that out-pace the physics engine or write your own collision system that predicts, ahead of time when the next collision will happen for each object.

Your specific problem happens all the time in AAA games as well, often when players do something that give them a speed that they were never meant to have within the game and BAAAM! You got caught inside a building, collision volume, fell through the world or got stuck half-way through a monster… insert funny graphics when the game is trying to resolve some of the situations :wink:

How do you rotate your cube? I could imagine that it makes a difference if you change transform.rotation or if you use forces.

This isn’t gossip, moving to support.

oups :frowning: … sorry for posting in the wrong section.

@Carpe-Denius … I am moving it using trnasform.rotation. I see what you are suggesting, I will try with force to check

EDIT : just tried setting angularVelocity instead of rotating transform but balls are passing through walls …

@Deon-Cadme … I naively understood PhysX 3.3 will solve my problems since Unity is stated “just check continuous detection and it works …” on their blogs. I will try to check and clamp balls velocity but my sample is not a bullet shot, balls and walls are not moving that fast

If you translate it by yourself and rotate the ball through your cube, physx doesn’t even have to check for collisions because you are “beaming” it to a new position. Try and rotate it with forces

I tried by setting angularVelocity to the rigidbody in Start but balls are always passing through

Maybe you are still bypassing the force calculations with that.

The methods you are looking for are AddTorque and/or AddRelativeTorque

You don’t have to use a script for testing, use the component “ConstantForce”.

Thank you for pointing out “ConstantForce” script and your help.
But unfortunately, same result with it.

Can you export your scene? I’ll test it

You should be changing the rigidbody’s rotation not the transform’s rotation. Changing the rigidbody’s position/rotation tells the physics engine that you are wanting to move through the physical world. If you change the transform’s position/rotation you “teleport” without any regard to physics.

It’s common and known problem with physx. Problem is that theres no easy way of fixing this. CCD is a must as you already know, next thing you should do is lower fixed timestep in Project Settings > Time. But be aware that it WILL lower performance, lower fixed timestep means that physx calculations are done more frequently and this of course means that it will need more cpu power. But its the only way to make physx more “precise”, and precision is what you need here, another thing you can try playing with is min penetration for penalty in Project Settings > Physics, but it’s last thing you should try, hope this helps :wink: