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
1
Question by zyrygon · May 29, 2017 at 06:31 AM · rigidbody2dcollider2d

Best solution for making arc collider

I'm making a game where I need to have multiple "arc" colliders on a parent ring that has a rigidbody, if the ring is rotated all the arcs should move as well, but the arcs can also be destroyed separately (in fact they are only deactivated for efficiency reasons).

I tried using edge collider 2d for making the arc but it seems to be problematic since points of the edge need to be reasonably big to cover the whole arc and this will cause the points on the outer edge of the arc to also cover a bit of area outside the arc, making the collider somewhat inaccurate.

It's easy to make a pretty accurate arc by having one arc object as a child of the ring, and having multiple children of this arc that only have a box collider. There seems to be some problems with this too, though. Sometimes when player object (a ball) hits the arc, arc gets deactivated as it's supposed to be, but player continues through it instead of bouncing. I'm not sure what exactly causes this behaviour but I suspect it might be the player hitting multiple colliders on same frame. Does anyone have a better theory?

Is there a way to have collider that's similar to multiple box colliders, but using only one collider? I considered mesh, but for certain reasons the rigidbody on the ring shouldn't be kinematic, and there's a problem with that and non-convex mesh collider. Can anyone suggest a smarter way for making accurate arc collider?

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 ZammyIsOnFire1 · Jun 04, 2019 at 10:00 AM 0
Share

Did you find any solution? I created an editor script that creates box colliders in circle which approximates arch colliders. Here I can share it:

 using UnityEditor;
 using UnityEngine;
 
 public class ArcColliderCreatorWindow : EditorWindow
 {
     public float Radius;
     public float SegSize = .25f;
     public int Layer;
     public string Tag;
     public Physic$$anonymous$$aterial Physic$$anonymous$$aterial;
 
 
     [$$anonymous$$enuItem("Tools/ArcColliderCreator")]
     public static void ShowWindow()
     {
         EditorWindow.GetWindow(typeof(ArcColliderCreatorWindow));
     }
 
     void OnGUI()
     {
         if (!Selection.activeGameObject)
             return;
             
         var selectedTransform = Selection.activeGameObject.transform;
         Radius = EditorGUILayout.FloatField("CircleRadius", Radius);
         SegSize = EditorGUILayout.FloatField("SegmentSize", SegSize);
         Layer = EditorGUILayout.LayerField("Layer", Layer);
         Tag = EditorGUILayout.TagField("Tag", Tag);
         Physic$$anonymous$$aterial = (Physic$$anonymous$$aterial)EditorGUILayout.ObjectField("Physic$$anonymous$$aterial", Physic$$anonymous$$aterial, typeof(Physic$$anonymous$$aterial), false);
 
         if (GUILayout.Button("Create"))
         {
             int created = 0;
             var c = Radius * 2 * $$anonymous$$athf.PI;
             float angleChange = 90 / ((c / 4) / SegSize);
 
             float angle = 0;
             float x = 0;
             float z = 0;
             do
             {
                 var go = GameObject.CreatePrimitive(PrimitiveType.Cube);
                 created++;
                 go.GetComponent<$$anonymous$$eshRenderer>().enabled = false;
                 go.name = "ArcSeg";
                 go.transform.SetParent(selectedTransform);
                 go.transform.localScale = new Vector3(SegSize, 1, SegSize);
                 x = Radius * $$anonymous$$athf.Cos(angle);
                 z = Radius * $$anonymous$$athf.Sin(angle);
                 go.layer = Layer;
                 go.tag = Tag;
                 go.GetComponent<BoxCollider>().material = Physic$$anonymous$$aterial;
 
                 go.transform.localPosition = new Vector3(x, 0, z);
                 go.transform.LookAt(selectedTransform.position);
 
                 angle += angleChange * $$anonymous$$athf.Deg2Rad;
             }
             while (angle < 90 * $$anonymous$$athf.Deg2Rad);
 
             Debug.Log("Created " + created);
         }
 
         if (GUILayout.Button("Delete"))
         {
             for (int i = selectedTransform.childCount - 1; i >= 0; i--)
             {
                 DestroyImmediate(selectedTransform.GetChild(i).gameObject);
             }
         }
     }
 }
 

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.

Follow this Question

Answers Answers and Comments

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Can I make mass and density constant independent of Collider 2D size? 1 Answer

Adding Collider2D changed physics on race car.How to compensate for mass loss in the back of the car?or do it some other way. 0 Answers

How do I get collisions between Tilemap Collider 2d and a Kinematic Rigidbody 2d? 1 Answer

Detect onMouseDown() on children colliders of a rigidbody parent 2 Answers

(2D) Can't use colliders when I have a kinematic rigidbody? 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