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 /
  • Help Room /
avatar image
0
Question by Shine_Bolt · Feb 22, 2019 at 12:09 AM · collider2dboundscapsule collider

CapsuleCollider2D.bounds empty

Whenever I try debuggging the following code, my bounds appear to be empty. The center, min, and max fields are all populated with the same values, and the size and extents are all 0.

 private Collider2D On() { return On(colmask.bounds); }
     private Collider2D On(Bounds bounds)
     {    const float EPSILON = 0.015f; //Mathf.Epsilon;
         LayerMask appropriate_layers = LayerMask.GetMask("Default", "Ground");//TODO make a constant value.
         
         return Physics2D.OverlapArea
         (    new Vector2(bounds.min.x + EPSILON, bounds.min.y),
             new Vector2(bounds.max.x - EPSILON, bounds.min.y - EPSILON),
             /*ContactFilter2D,*/
             /*results,*/ //This is where the results go on some functions, can be ignored since I only need to know that there was a collision.
             appropriate_layers
         );
     }

The properties window starkly disagrees with these values, but I'm still only able to jump once in a blue moon (apparently depending on my position, and rotation, which shouldn't matter since I am using bounds). alt text

Finally, here's the Update function I am calling the function from.

 void Update ()
     {    dx = Input.GetAxis("Horizontal") * speed;
         /**/ if (dx > 0) Cx =  1;
         else if (0 > dx) Cx = -1;
         
         var floor_collider = On( /*BoundsColliders(gameObject)*/ );
         if (floor_collider!= null)
         {    var floor = floor_collider.gameObject;
             if (Input.GetButtonDown("Jump")) Jump();
             if(floor.tag == "Enemy" && floor.transform.position.y < y)
             {    var atk = floor.GetComponent<Enemy>().vigor.Attack(attack_power);
                 if( Health.Atk.DIES == atk ) Destroy(floor);
             }
             
             //aligns character to the ground it is standing on
             ContactPoint2D[] contacts = new ContactPoint2D[1];
             Physics2D.GetContacts(floor_collider, colmask, new ContactFilter2D(), contacts);
             var norm = contacts[0].normal;
             if (norm != Vector2.zero) transform.rotation = Quaternion.FromToRotation(Vector2.up, norm);//Rotate the sprite
         }
 
         //if (Input.GetButton("Fire1") && Time.time > next_missle) Fire();
         if (Input.GetButton("Fire1")) AutoFire();
     }

So why do my extents appear to be 0, and why can't I jump?

capturex.png (17.5 kB)
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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Shine_Bolt · May 09, 2019 at 01:43 AM

I figured it out! Whenever I used GetComponent() I was getting the disabled BoxCollider2D, which has empty bounds because it is disabled. I didn't realize GetComponent could get disabled components.

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

168 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

Related Questions

How can i check that is an object is withhin a collider? JS 1 Answer

When is OnTriggerExit2D called? 1 Answer

Changing a SpriteRenderer's Bounds 0 Answers

Limit object movement inside donut 0 Answers

CAPSULE COLLIDER BUG!!! (MIXAMO FUSE CHARACTER) 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