I have a terrain and a basic cube, what do I need to do so that the cube will fall due to gravity and stop for the terrain or other objects? I will likely have a few objects in the game at any time. I need the cube, or cubes to fall and not fall through the world, also for one cube to collide with other cubes. Also, if a cube falls on a slope such that the incline is great enough, it should roll or slide down the incline until it stops. At this point, I am thinking that isnt a feature in Unity and that I might have to code it in myself. Before I embark on that, thought I would ask about it.
3 Answers
3Just put a rigidbody component on those objects that you would like to apply gravity and put colliders on the objects that you dont want to be “ghosts”. I think that is it. From here the PhysX engine will do the rest
I did that... I think it might be something with the mesh collider, or somehow the mesh itself?
– ccrhAlright, so I feel very silly about this, but I was messing around with it and apparently by enabling the “convex” option in the mesh collider for the object, I now have the objects successfully staying on top of the terrain and not falling through… Thanks for your help!
If you have cubes dont use mesh collider. Use box collider instead. In general, try to dont use mesh collider unless if you very desperate. Usually most of the shapes can be created with the primitive colliders(box,sphere,capsule). If you can always use these ones
– dsadaThats what I was afraid of. I was hoping I could design all of the items I would use in Autodesk Inventor... then export them as .stls which Blender can work with, then export them from Blender as .dae (I dont know if there is a better way to do this), which I can import into Unity. I dont know if there is a better way to do all of this... I just feel comfortable designing 3D objects in Inventor, I have been using that for years. I am going to have to look into it, because I would bet there are MUCH better ways to create and design 3d objects than the monstrosity I described above.
– ccrhIf you imported the terrain from blender or some external tool into Unity ,
Try increasing the Scale of the terrain, and also note that colliders wont work if the size of the mesh is less than 0.5.
For more Detailed description, try creating a cube first and then import the terrain.
Change the size of the terrain corresponding to the cube.
Add Mesh Collider to the terrain, Add Rigidbody to the cube.
Then the Gravity will work fine.
This is trivial with the inbuilt physics engine. Add a rigidbody and box collider to the cube. Add a mesh collider to the terrain. Click play.
– tanoshimiI have a terrain collider and a rigidbody on the terrain and on the cube, well, its more of a 2"x4"x4' shape with a rigidbody and a mesh collider that uses the matching mesh. I had the cube/2x4 set to kinematic, freezing it and I was able to walk on it with the character but I couldnt get it to fall without falling through the world. Is there a way to do this with models that arent default cubes or such?
– ccrh