- Home /
How to automatically add physics/colliders to a model of a map
Hi there,
I have a 3ds model of a village and have imported this onto my scene. As originally anticipated, I knew my character would simply fall/walk through everything. For now, I've added a plane on the floor so that he can at least tread the village's surface.
I wanted to know if there's any possible in-built mechanic or efficient way of adding the necessary physics/colliders to my village model? I really want to avoid adding physics/colliders to every element of the village (such as fences, houses, slopes, hills etc). Is there a way of Unity detecting objects and obstacles of this model?
Many thanks for your time in advance.
Answer by VesuvianPrime · Sep 11, 2014 at 12:23 PM
As a temporary measure you can use a MeshCollider
With regards to adding colliders to the individual pieces that make up your terrain, I think you're either going to have to go fully automatic or fully manual.
You could recurse through the asset tree and add collision boxes to each item, or you could manually go through the tree and add colliders to each item. I'm not sure there is a half-way solution here.
Thanks for your reply @VesuvianPrime. I've added a $$anonymous$$esh Collider, but my character can still walk through things. Is this something to do with the $$anonymous$$esh and/or $$anonymous$$aterial fields? I've read the documentation and cannot extract any useful information from it to solve this problem.
Also, what do you mean by fully automatic? I understand what you mean by manually doing this, but what you've described as automatically doing it sounds the same as manually doing it. Thanks.
You will need to assign the terrain mesh to be the collision mesh on the $$anonymous$$eshCollider to get anything useful out of it.
By fully automatic, I mean writing an editor script to loop through the asset and add colliders. Honestly, it would probably take longer to write the script than to do it manually. Besides, with the manual approach you'll be able to get the colliders exactly as you want them.
I see, thank you. I'll avoid the automatic method and do it manually if this $$anonymous$$eshCollider method doesn't work.
With regards to the $$anonymous$$eshCollider method, apologies for the rookie question, but where do I locate the terrain mesh for this model? When I've created actual terrains in the past, the terrain mesh for each is present. However, as this is simply a 3ds model (GameObject), I believe there is no terrain mesh allocated to it.
Thanks for your support and swift replies.
If you look at your GameObject you should see a $$anonymous$$eshFilter Component. This $$anonymous$$eshFilter will contain the $$anonymous$$esh that represents your terrain. If you click the $$anonymous$$esh it should highlight the location in the project view.
Alternatively, if you click the dot next to the $$anonymous$$esh field in the inspector it will open a new menu that lists all of the $$anonymous$$eshes in your project. You can search and filter through this to find your terrain mesh.
Nearly there! So I've located the $$anonymous$$esh that was in the $$anonymous$$eshFilter component of my GameObject. However, this is not the mesh that represents my entire terrain, rather only a small door/sign of the terrain (strange).
Regardless, I found a $$anonymous$$esh that captured a lot of the terrain, but still not all of its entirety - I've assigned this to the Collision $$anonymous$$esh field anyway. As we can only assign one $$anonymous$$esh to the Collision $$anonymous$$esh, would this mean I'd have to create manual colliders for the remaining objects? $$anonymous$$any thanks.
Your answer
Follow this Question
Related Questions
Disable/Enable Colliders 1 Answer
No Collision 3 Answers
object goes through another object error 1 Answer
Is there anyway to see if another Object has any Collision? 1 Answer
How to check if two objects are mutually ignoring collision? 0 Answers