• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by jedaniels000 · May 11, 2020 at 08:24 AM · collisioncollision detectionmeshcollidermesh collider

Mesh Collider collision problem

I am generating a mesh surface for my player to walk on in chunks; for each chunk, the code below is run. My issue is that the player (also tested cube & sphere with and without rigidbody) goes right through the floor (also raycasts won't collide with the mesh). I have scoured the internet for a solution; OnTrigger is not enabled and the mesh is in the default layer. However, the part I really don't understand is if I pause the game and manually add a mesh collider to the floor, the objects will collide with the floor then. I've compared the two colliders (script generated and manually generated) and they appear identical. Any pointers would be greatly appreciated.

 meshFilter = GetComponent<MeshFilter> ();
 meshRenderer = GetComponent<MeshRenderer> ();
 meshCollider = GetComponent<MeshCollider> ();
 
 // if there's not a mesh filter, add one
 if (meshFilter == null) {
     meshFilter = gameObject.AddComponent<MeshFilter> ();
 }
 
 // if there's not a mesh renderer, add one
 if (meshRenderer == null) {
     meshRenderer = gameObject.AddComponent<MeshRenderer> ();
 }
 
 // if there's not a mesh collider and we want one, add one
 if (meshCollider == null && colliderOn) {
     meshCollider = gameObject.AddComponent<MeshCollider> ();
 }
 
 // If there's a mesh collider and we don't want one, destroy it
 if (meshCollider != null && !colliderOn) {
     DestroyImmediate (meshCollider);
 }
 
 // Get the mesh
 mesh = GetComponent<Mesh>();
 // If there's no mesh, add a mesh
 if (mesh == null) {
     mesh = new Mesh ();
     meshFilter.sharedMesh = mesh;
 }
 
 if (colliderOn) {
     if (meshCollider.sharedMesh == null) {
         meshCollider.sharedMesh = mesh;
         meshCollider.material = null;
     }            
 }
 
 meshRenderer.material = chunkMaterial;
Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

198 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Very Confused About Convex Mesh Collider Result 0 Answers

[SOLVED] Why is this procedurally generated mesh not colliding? 2 Answers

Correct position of overlapping meshes 0 Answers

Detect collision between kinamatic rigidbodie and gameobject without rigidbody but with colliders 0 Answers

Problems with object collision detection using mesh colliders 0 Answers

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges