Justin808
Justin808

Reputation: 21512

How to prevent a Ridigbody from going through walls?

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?

enter image description here

I've tried:

I'm staring to wonder if the UNity3d Physics system works at all :/

Upvotes: 3

Views: 5721

Answers (2)

Justin808
Justin808

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

Programmer
Programmer

Reputation: 125255

Too many things could be the problem try of these one by one and see which one works for you.

  1. If you want to use Mesh Colliders with convex, RigidBody Must be attached to it. Attach RigidBody to both Object.

  2. 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.

  3. Since it works sometimes but fails other times, change both the wall and the ship's the RigidBody Collision Detection to Continuous Dynamic.

  4. 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

Related Questions