Reputation: 21512
I've got a ship thats a Rigidbody
. The ship has a MeshCollider
on it. This collider is set as Convex.
I've got the ground thats a programmatically created Mesh
. That Mesh has aMeshCollider
on it. This collider is not set as Convex.
Most of the time, this works. I don't fall through the floor. About 40% of the time I can drive through the walls.
Trying to solve this, for each wall section I added a child GameObject
marked as static. This GameObject
has a BoxCollider
on it. I've sized the collider to be 0.1 larger than the section of the wall. This means the colliders overlap, and there should be no gap to fall through.
As you can see in the image below, I'm still able to drive through the wall some times.
What should I be doing so I can't drive through the walls?
I've tried:
Adding a Rigidbody
to the ground as well, marked as kinematic. To do this I removed the MeshCollider
all together and used all BoxCollider
s. I had to use all BoxCollider
s as you can have a Convex Rigidbody. This didn't solve the issue.
I Removed the MeshCollider
from the player and use a single BoxCollider
. At this point there are no longer any MeshCollider
s in the scene. This didn't solve the issue.
Both Rigidbody
s are set to Continuous Collision Detection.
I'm staring to wonder if the UNity3d Physics system works at all :/
Upvotes: 3
Views: 5721
Reputation: 21512
Adjust the fixed and maximum allowed timestep. I set the "Fixed Timestamp" to 0.0005
http://docs.unity3d.com/Manual/class-TimeManager.html
Upvotes: 0
Reputation: 125255
Too many things could be the problem try of these one by one and see which one works for you.
If you want to use Mesh Colliders with convex, RigidBody Must be attached to it. Attach RigidBody to both Object.
Because you are generating walls with code, make sure that the wall you are assigning Mesh Collider has <= 255 triangles.Convex Mesh Colliders are limited to 255 triangles. If the triangles of the Wall > 255,convex will fail.
Since it works sometimes but fails other times, change both the wall and the ship's the RigidBody Collision Detection to Continuous Dynamic.
Use Compound Colliders. Remove the Mesh Collider on the Ship and use multiple Box Colliders around your ship to get the desired feel of what you want.
Upvotes: 2