Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 KholdStare2399 · Jul 08, 2014 at 10:04 AM · platformsplatform-support

Drop through platform script

I am trying to make a script to drop through certain platforms. I have got it to almost work using collider2d.enabled = false; The problem is it only turns off one of the colliders on my character and I need it to turn off 2 colliders. Is there a way to specify which collider it should turn off? Here is the code for it so far

 //platform fallthrough script
         if (allowPlatformDropThrough) {
                         foreach (Transform groundCheck in groundChecks) {
                                 RaycastHit2D fallThrough = Physics2D.Linecast (transform.position, groundCheck.position, 1 << LayerMask.NameToLayer ("fallThrough"));
                                 if (grounded && fallThrough && Input.GetAxis ("Vertical") < 0) {
                                         //rigidbody2D.collisionDetectionMode = false;
                                         collider2D.enabled = false;
 
                                 }
                                 if (!fallThrough) {
                                         collider2D.enabled = true;
                                 }
                         }
                 }
Comment
Add comment · Show 2
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 Dudledok · Jul 08, 2014 at 10:11 AM 0
Share

About using more than one collider see here: http://answers.unity3d.com/questions/188775/having-more-than-one-collider-in-a-gameobject.html

Why do you need more than one collider?

avatar image KholdStare2399 · Jul 08, 2014 at 10:20 AM 0
Share

the character has a box collider for their body and a circle collider for their feet. This is all done in 2d so the characters feet don't get caught on tiny edges.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by tarasfromlviv · Jul 08, 2014 at 10:20 AM

You can just disable all the colliders at once.

 var colliders = GetComponents<Collider2D>();
 foreach (var col in colliders)
 {
     collider.enabled = false;
 }

You can also check whether the collider isTrigger inside loop to avoid turning off triggers or check col is BoxCollider2D for instance to check if it is a collider of specific type.

Comment
Add comment · Show 3 · 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 KholdStare2399 · Jul 08, 2014 at 10:29 AM 0
Share

I'm very new to scripting so all of that code was just a guess. I tried to add the bit you suggested but it still only seems to turn off the first collider in the inspector list. I added public Collider2D[] col; to the variables and attached each collider2d and modified the code to the following

 //platform fallthrough script
         if (allowPlatformDropThrough) {
                         foreach (Transform groundCheck in groundChecks) {
                                 RaycastHit2D fallThrough = Physics2D.Linecast (transform.position, groundCheck.position, 1 << Layer$$anonymous$$ask.NameToLayer ("fallThrough"));
                                 if (grounded && fallThrough && Input.GetAxis ("Vertical") < 0) {
                                     var colliders = GetComponents<Collider2D>();
                                     foreach (var col in colliders)
                                         {
                                             collider2D.enabled = false;
                                     }
 
                                 }
                                 if (!fallThrough) {
                                         collider2D.enabled = true;
                                 }
 
 
                         }
                 }
avatar image KholdStare2399 · Jul 08, 2014 at 10:31 AM 0
Share

I could add the full character controller code if you think it would help. It's a mess though.

avatar image KholdStare2399 · Jul 12, 2014 at 03:12 AM 0
Share

Does anyone have an idea of how to disable all the colliders on a gameObject?

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

2D Bouncing Platforms w/o Rigidbody 0 Answers

What is the difference between these platforms: PC, Mac, Linux Standalone / Windows Build Support (IL2CPP) / Universal Windows Platform Build Support? 0 Answers

A place to specify my asset's supported platforms when publishing. 0 Answers

Sync assets that are built in different platforms 0 Answers

When will Unity officially support Windows 8 and Windows Phone 8 platforms? 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