Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • 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 jamesEffects · Jan 05, 2018 at 06:54 AM · collidermeshcolliderboundsboxcolliderintersection

Mesh collider not working as expected

Im trying to detect intersecting gameobjects. I have a simple scene with 4 blocks and a shape. The blocks have box colliders and the shape a mesh collider.

If the shape is intersecting a block it should turn the block red otherwise it should remain blue. For some reason I can't get this to work, it's as if the mesh collider is not accurate enough.


alt text With the image on the left, I would expect the bottom left block to be blue as it's not intersecting the green shape; but it's not. If I drag the shape to the right (right image) the left side blocks turn blue which makes me think the code is working in some form.

Any help would be much appreciated!

Code:

 using UnityEngine;
 using System.Collections;
 using System.Collections.Generic;
 
 public class gameController : MonoBehaviour {
 
     public GameObject shape;
 
     public GameObject blockA;
     public GameObject blockB;
     public GameObject blockC;
     public GameObject blockD;
 
     public Material red;
     public Material blue;
 
     List<GameObject> blockList;
 
     // Use this for initialization
     void Start () {
         blockList = new List<GameObject>();
         blockList.Add (blockA);
         blockList.Add (blockB);
         blockList.Add (blockC);
         blockList.Add (blockD);
 
     }
     
     // Update is called once per frame
     void Update () {
 
         MeshCollider shape_collider = shape.GetComponent<MeshCollider> ();
         foreach (GameObject block in blockList) {
             BoxCollider block_collider = block.GetComponent<BoxCollider> ();
 
             if (shape_collider.bounds.Intersects (block_collider.bounds)) {
                 block.GetComponent<Renderer> ().material = red;
 
             } else {
                 block.GetComponent<Renderer> ().material = blue;
             }
         }
     }
 }
 


intersectexample.png (167.0 kB)
intersectexample.png (167.0 kB)
Comment
Add comment · Show 1
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
avatar image nt314p · Feb 21, 2018 at 11:24 PM 1
Share

Could you post your inspector of the GameObject?

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by WbrJr · Feb 21, 2018 at 07:22 PM

Hey there,

Do you have "convex" enabled on your meshcollider? If so, turn it of and i think it should work...

have a nice day and good luck

Comment
Add comment · Share
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
avatar image
0

Answer by JedBeryll · Feb 21, 2018 at 08:56 PM

Not exactly a solution but you could make this work with 2 box colliders. Multiple colliders under 1 object works like it's 1 collider. It's better performance-wise too.

Comment
Add comment · Share
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

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.

Follow this Question

Answers Answers and Comments

88 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

Related Questions

Get EXACT SkinnedMeshRenderer bounds 2 Answers

Mesh.CombineMeshes - what happens to colliders? 0 Answers

Bounds and unwanted offset 0 Answers

How to set parent collider equal to child collider visually? 2 Answers

Collider2d.bounds.Intersects not detecting intersection 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges