• 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
Question by mouser013 · Jul 13, 2015 at 11:50 PM · collisioncollidercharactercontroller

Disable collision between mesh collider and character controller

So I have a door and the standard fps controller and I can open the door, slerping it 90deg. I want to disable collision between the door and the player so that if the player is in the way when the door is rotating, the door goes through the player. The door has a mesh collider and a capsule collider trigger. I set a bool var when the door is activated and unset it if the door has reached a close angle/open angle.

So far, I've tried using physics.ignorecollision(), disabling the door's mesh collider and even removing the collider component entirely when the bool var is set but nothing seems to work. I'm assuming the problem is in the way I'm rotating the door i.e. changing localRotation. Any help please?

Comment

People who like this

0 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 mouser013 · Jul 13, 2015 at 01:08 PM 0
Share

uhh...bump?

3 Replies

  • Sort: 
avatar image
Best Answer

Answer by mouser013 · Jul 15, 2015 at 02:53 PM

Okay, I figured it out. I forgot that the door object had child meshes with colliders and changing the layer of the parent doesn't affect the children. I updated the script to go through the children and change their layers and now it works fine.

Comment
Aridez

People who like this

-1 Show 1 · 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 Aridez · Jul 15, 2015 at 03:54 PM 0
Share

Glad to hear it is finally working! I think that you should mark as answer the one below where all the conversation went on for clarity tho.

avatar image

Answer by Aridez · Jul 14, 2015 at 01:05 AM

In unity menu at the top, on Edit>Project settings>Physics you can find something called layer collision matrix. To avoid collisions create a layer called "Player" for your player and another called "Doors" (for example) and put all the doors in this second layer, then go to the layer collision matrix and uncheck the Player-Doors checkbox.

Comment
NEOF
nadhimali
mouser013

People who like this

3 Show 5 · 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 mouser013 · Jul 14, 2015 at 07:48 AM 0
Share

I want to ignore collision only when a bool is set, not all the time.

avatar image Aridez · Jul 14, 2015 at 02:17 PM 1
Share

What's exactly the situation? I guess that you want the collision only when the door is closed, in that case, while the doors are closed you can put them on a "Wall" layer (or some other special layer if you want some special interactions with closed doors) and then when opening you could change the layer to "Door" or "OpenedDoor" or something like that. While closed it would act as a wall and while opening the collisions would be ignored.

avatar image mouser013 · Jul 15, 2015 at 08:48 AM 0
Share

I don't want collision while the door is moving. I tried changing the layer before starting to rotate the door and changing it back after but that didn't work either.

avatar image Aridez · Jul 15, 2015 at 12:20 PM 1
Share

I found some code that might be useful for you here, changing the layers as I said should be working so maybe something is wrong in your code. Try this: (I took the code from the other question)

  if (ghostMode){ 
     gameObject.layer = 8; // move to ghost layer
   } else { 
     gameObject.layer = 0; // move to regular layer
   }

Adapt it to your case and if you still have problems let me know and we'll try to see what's going wrong, good luck!

avatar image mouser013 · Jul 15, 2015 at 02:23 PM 0
Share

Changing to the new layer works if I do it beforehand. But it doesn't work if I do it ingame.

Here's the relevant part:

     void Update()
     {
         if (active && Input.GetButtonDown ("Interact")) 
         
         {
             if(!isLocked)
             {
                 if(isOpen)
                 {
                     gameObject.layer = 9;
                     isOpen = false;
                 }
                 else
                 {
                     gameObject.layer = 9;
                     isOpen = true;
                 }
                 complete = false;
             }
             else
             {
                 StartCoroutine (InfoText ());
             }
         }
 
         if(!complete)
         {
             if(isOpen)
             {
                 transform.localRotation = Quaternion.Slerp (transform.localRotation,openAngle,Time.deltaTime * smoothing);
             }
             else
             {
                 transform.localRotation = Quaternion.Slerp (transform.localRotation,closeAngle,Time.deltaTime * smoothing);
             }
 
             if ((isOpen && Quaternion.Angle (transform.localRotation,openAngle) < 1 ) || (!isOpen && Quaternion.Angle(transform.localRotation,closeAngle) < 1))
             {
                 gameObject.layer = 0;
                 complete = true;
             }
         }
     }
 


The idea is to ignore collision while complete is false.

EDIT: I just tried changing to the new layer in an Awake() and it turns out it had no effect. The layer had changed in the inspector but the player would still collide with the door.

FURTHER EDIT: Disregard. I figured it out. Thanks!

avatar image

Answer by zedseven · Jul 15, 2015 at 03:46 PM

Why don't you just disable the door's mesh collider?

 door.GetComponent<MeshCollider>().enabled = false;

~zedseven

Comment

People who like this

0 Show 1 · 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 mouser013 · Jul 15, 2015 at 03:51 PM 0
Share

I still need the collider for other stuff. Anyway I've figured out what went wrong.

Unity Answers is in Read-Only mode

Unity Answers content will be migrated to a new Community platform and we are aiming to launch a public beta by June 9. Please note, Unity Answers is now in read-only so we can prepare for the final data migration.

For more information and updates, please read our full announcement thread in the Unity Forum.

Follow this Question

Answers Answers and Comments

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

When using a character controller for the player, can other colliders be used alongside the character controller? 1 Answer

Problem with rigidbodys and box collider 1 Answer

Deform Charater controler Collider acording to stance 1 Answer

Can a CharacterController ignore one or more Colliders? 2 Answers

Multiple Colliders Performance 2 Answers


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