Using a mesh collider in Unity with Bullet Physics - unity3d

When using this ramp as a collider with Convex Hull the ball rolls on the edge like this:
Ramp and ball
Bullet physics settings
Blender
Thanks!
/T

Because that is not a convex shape.

Thanks! The creator of the plugin gave this solution to the shape:
approximate the shape with multiple simple colliders (boxes)
use BVHTriangleMeshShape if it is static
use the GImpactTriangleMeshShape if it is dynamic

Related

Unity3D Collider Passing Through Other Colliders

The Problem: Mesh colliders on some rigidbody objects are passing through colliders on other objects.
Things I have tried:
With the assumption A is a GameObject with a RigidBody attached and B is a normal GameObject with a collider.
Give A a convex mesh collider
Give A a non-convex mesh collider
Give B a convex mesh collider
Give B a non-convex mesh collider
give B a box collider
give B a convex mesh and box collider
give B a non-convex mesh and box collider
Adjusting the weight of the rigidbody
I have tried all of these in all combinations of A and B.
In addition,
Colliders are not marked as triggers
All objects are on the default layer (0)
Checking isKinematic; doing this seemed to make gravity stop affecting the object, so I have left it as false.
Constraints: I want A to use a mesh collider since most of the objects involved are moderately complex, and fitting other colliders to them would take a while.
Weird Behaviour: I have some objects with both rigidbody and convex mesh collider where the collision is working fine with a non-convex mesh collider. This is inconsistent with other gameobjects. The objects have all of the same settings.
I am using unity version 2019.3.11f1 if that is relevant.
The object being used are from this package. Specifically, the filing cabinet with rigidbodies on the drawers works fine. The desk, office chair, pen, and open laptop all fall through the "floor" (a cube with all of the above colliders tested on it).
Do you have 'isKinematic' checked on the objects with rigidbodies that are going through other colliders? If so uncheck it so that external forces affect it.
edit you also need to click convex on the mesh colliders if they are colliding with other mesh colliders, Convex Mesh Colliders are limited to 255 triangles, are the objects that are not passing through have more than 255 triangles in geometry?
I am Assuming you have set your Collision Detection to Discrete In your gameObject's RigidBody, if so, please make sure to select Collision Detection to Continuous In your gameObject's RigidBody.
Reason Why this is not working
You are trying to use collision that has (speed > your Computer's frame speed) so, the frame is not catching the collider properly some time catches and some time fails to catch.
You are moving your GameObjects with tranform.translate or position etc. If so then make sure to use Rigidbody Related function for Positioning, rotating.
Solution Image For First Problem
I'm assuming
-you game object which contain the mesh component is very small ( bellow 0.7 size(x,y,z) so the game engine is little difficult to detect it)
and also
for the colliding objects at-least one rigid-body component must be attach to one object
This seems to be a common big problem, and I have been struggling with the same issue for days, and have finally fixed it, so am feeling like I should highlight one important thing:
move Rigidbody via MovePosition, not via just changing its position field directly, nor via changing position of GameObject holding it.
Changing position via "wrong" ways will "teleport" your rigidbody, physics won't fully work on it in that case.

Blender import in Unity, how to generate correct mesh collider?

How to get/generate a proper mesh collider in Unity using a model exported from Blender (.obj/.fbx)?
This is my second day using Blender and I'm hitting a roadblock. I've tried fiddling with the Rigid Body Collisions, i.e., setting "Shape" to Convex Hull and "Source" to Final/Deformed (Blender docs specify that these two settings capture modifiers), I've tried "Generate Colliders" inside Unity and the mesh collider always comes out as above. A box.
How to assign mesh collider to the exact mesh? I started with a circle and used a boolean modifier to create the cutout. Desire is to have the mesh collider around the mesh exactly, meaning no collider on the cutout. How to do this?
Make sure you have a Mesh Collider component on your object with the correct mesh set. Watch out for the convex parameter for flat objects, as it can sometimes fail and give you a box collider instead.
Edit:
I just noticed you said you were using a RigidBody, which means you need to have Convex set. A solution to this is to make a second mesh in Blender with a third dimension to it, then set the flat one on the Mesh Filter and the one with thickness to the Mesh Collider.
In importing a .obj or a .fbx, select the asset. make sure you have generate colliders selected.
Here I have imported an FBX into unity, but there are no colliders.
Sellect the asset, and turn on generate colliders if you want a collider around the mesh:

How to add reaction force to a collision in Unity?

So when using rigidbody physics on a 2d sphere and a spinning animated 2d rectangle it only pushes the sphere aside when it collides. What I'm wanting is the sphere to fly off when collided (don't ask if it's if it's a problem with it colliding or not).
I've tried the physics materials and adjusting the rigidbody and such but nothing works. There's not a single thing online about it so attempting to code physics would be very difficult.
If I understand correctly.
You could apply AddForce or AddForceAtPosition function with ForceMode.Impulse argument to sphere when Collider2D.OnCollisionEnter2D(Collision2D) event trigger.
Or Just modify sphere speed when Collider2D.OnCollisionEnter2D(Collision2D) event trigger.
Note that Collision2D have contacts and relativeVelocity which may help you calc the force vector.

Unity limit physics walkable area to navmesh mesh

I'm using physics to control my players and navmesh/agent for AI NPCs and occasional player movement. I'm wondering if there is a way to limit my walkable area for the player, when using physics to move, to the exact baked mesh from the navmesh so that the coverable ground is constant between the two.
Thanks in advance
One way could be to get the actually mesh in the navmesh and construct some sort of collision from it. You can get the actual mesh like this:
UnityEngine.AI.NavMeshTriangulation triangulatedNavMesh = UnityEngine.AI.NavMesh.CalculateTriangulation();
Mesh mesh = new Mesh();
mesh.name = "ExportedNavMesh";
mesh.vertices = triangulatedNavMesh.vertices;
mesh.triangles = triangulatedNavMesh.indices;
Then a recommendation for C# trigonometry calculations (like finding the convex hull and such) is NetTopologySuite

AndEngine collision detection

I want to detect sprite collision on a hill but my sprite detect collision before hill as it detects rectangular shape. I want to detect collision on hill edges, I draw a triangle by using mesh but collideswith() method not working
You have two options:
1) You can use the Box2D extension and let Box2D handle the colisons
2) You can use the AndEngineCollisionExtension
-You'll have to replace your Sprite with PixelPerfectSprite