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 rustyruss1985 · May 14, 2018 at 02:07 AM · android buildphysics2dboxcollider2dpolygoncollider2d

polygoncollider2d does not work on device?

Hello, i'm using a polygoncollider2d on my sprites, so my collisions will be more accurate (Adhering to the outline of the sprite). this works well when i test in the editor (my sprite only bounces when the opaque pixels collide with an object), but when i build to my device, it appears to go back to be using a box collider or something else (it bounces when the outline of my square sprite tile touches an object, like its using a box collider).

anyone else ever experience this? here is the code i'm using for the class with the collisions..

 public Character()
     {
 
         Physics2D.gravity = Vector2.zero;
         //Physics2D.velocityThreshold = 0.001f;
 
 
 
         physicsMaterial = new PhysicsMaterial2D();
         //physicsMaterial.bounciness = 1;
 
 
         bodyWeaponSprites = Resources.LoadAll<Sprite>("bodyweapongrid");
         weaponBodySprites = Resources.LoadAll<Sprite>("weaponbodygrid");
         bodySprites = Resources.LoadAll<Sprite>("bodygrid");
         weaponSprites = Resources.LoadAll<Sprite>("weapongrid");
 
         bodyWeaponObject = new GameObject();
         weaponBodyObject = new GameObject();
         bodySpriteObject = new GameObject();
         weaponSpriteObject = new GameObject();
 
 
         bodyWeaponObject.AddComponent<SpriteRenderer>();
         bodyWeaponObject.GetComponent<SpriteRenderer>().sprite = bodyWeaponSprites[0];
         //  bodyWeaponObject.AddComponent<Rigidbody2D>();
         bodyWeaponObject.AddComponent<PolygonCollider2D>();
         bodyWeaponObject.GetComponent<PolygonCollider2D>().sharedMaterial = physicsMaterial;
 
 
 
         bodySpriteObject.AddComponent<SpriteRenderer>();
         bodySpriteObject.GetComponent<SpriteRenderer>().sprite = bodySprites[0];
         bodySpriteObject.AddComponent<Rigidbody2D>();
         bodySpriteObject.AddComponent<PolygonCollider2D>();
         bodySpriteObject.GetComponent<PolygonCollider2D>().sharedMaterial = physicsMaterial;
 
         bodySpriteObject.AddComponent<Hit>();
 
         bodyWeaponObject.transform.parent = bodySpriteObject.transform;
         //bodySpriteObject.transform.parent = bodyWeaponObject.transform; 
 
         Physics2D.IgnoreCollision(bodySpriteObject.GetComponent<PolygonCollider2D>(), bodyWeaponObject.GetComponent<PolygonCollider2D>(), true);
 
 
         weaponBodyObject.AddComponent<SpriteRenderer>();
         weaponBodyObject.GetComponent<SpriteRenderer>().sprite = weaponBodySprites[0];
         weaponBodyObject.AddComponent<Rigidbody2D>();
         weaponBodyObject.AddComponent<PolygonCollider2D>();
         weaponBodyObject.GetComponent<PolygonCollider2D>().sharedMaterial = physicsMaterial;
 
         weaponSpriteObject.AddComponent<SpriteRenderer>();
         weaponSpriteObject.GetComponent<SpriteRenderer>().sprite = weaponSprites[0];
         //weaponSpriteObject.AddComponent<Rigidbody2D>();
 
 
         weaponBodyObject.SetActive(false);
         weaponSpriteObject.SetActive(false);
 
         weaponSpriteObject.transform.parent = weaponBodyObject.transform;
 
         Physics2D.IgnoreCollision(weaponBodyObject.GetComponent<PolygonCollider2D>(), weaponBodyObject.GetComponent<PolygonCollider2D>(), true);
 
         weaponColliders = new PolygonCollider2D[16];
         for (int i = 0; i < 16; i++)
         {
             weaponSpriteObject.GetComponent<SpriteRenderer>().sprite = weaponSprites[i];
             PolygonCollider2D collider = weaponSpriteObject.AddComponent<PolygonCollider2D>();
             collider.sharedMaterial = physicsMaterial;
             weaponColliders[i] = collider;
         }
 
     }
 
     public void Update()
     {
         if (attacking == true)
         {
             ContinueAttack();
         }
 
 
     }
 
 
     public void UpdateRotation(int newAngle)
     {
         bodySpriteObject.transform.rotation = Quaternion.Euler(0f, 0f, newAngle);
         //bodyWeaponObject.transform.rotation = Quaternion.Euler(0f, 0f, newAngle); 
 
     }
 
     public void UpdatePosition(Vector3 newPositionVector)
     {
         if (moving == true)
         {
             bodySpriteObject.GetComponent<Rigidbody2D>().velocity = new Vector3();
             bodySpriteObject.transform.position += newPositionVector * 1 * Time.deltaTime;
         }
         //bodyWeaponObject.GetComponent<Rigidbody2D>().velocity = new Vector3();
         //bodyWeaponObject.transform.position += newPositionVector * 1 * Time.deltaTime;
     }
 
 
 
     public void UpdateSprite(int spriteIndex)
     {
         bodySpriteObject.GetComponent<SpriteRenderer>().sprite = bodySprites[spriteIndex];
         //bodyWeaponObject.GetComponent<SpriteRenderer>().sprite = bodyWeaponSprites[spriteIndex];
 
     }
 
     public void OnAttack()
     {
         attacking = true; 
 
         bodyWeaponObject.SetActive(false);
         bodySpriteObject.SetActive(false);
 
         weaponBodyObject.transform.localRotation = bodySpriteObject.transform.localRotation;
         weaponBodyObject.transform.position = bodySpriteObject.transform.position; 
 
         weaponSpriteObject.SetActive(true);
         weaponBodyObject.SetActive(true);
 
         attackIndex = 0; 
     }
 
     public void ContinueAttack()
     {
         weaponSpriteObject.GetComponent<SpriteRenderer>().sprite = weaponSprites[(int)attackIndex%16];
         weaponBodyObject.GetComponent<SpriteRenderer>().sprite = weaponBodySprites[(int)attackIndex%16];
 
         for (int i = 0; i < weaponColliders.Length; i++)
         {
             if (i == (int)attackIndex % 16)
                 weaponColliders[i].enabled = true;
             else weaponColliders[i].enabled = false; 
         }
 
         attackIndex += 0.2f; 
     }
 
     public void EndAttack()
     {
         Debug.Log("Ending Attack");
 
         attacking = false; 
 
         bodyWeaponObject.SetActive(true);
         bodySpriteObject.SetActive(true);
 
         weaponSpriteObject.SetActive(false);
         weaponBodyObject.SetActive(false);
     }
 
     public void EndMovement()
     {
         moving = false; 
     }
Comment
Add comment · Show 3
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 rustyruss1985 · May 14, 2018 at 02:13 AM 0
Share

ok so apparently this was fixed in 2014 in unity 4.6?

https://issuetracker.unity3d.com/issues/runtime-polygoncollider2d-generation-on-android-is-different-than-in-editor

doesn't seem to be fixed at all. i came across this solution though: https://answers.unity.com/questions/1093169/does-polygoncollider2doverlappoint-perform-differe.html

avatar image TanselAltinel · May 14, 2018 at 08:56 AM 0
Share

Did you set your texture to Read/Write enabled?

avatar image rustyruss1985 TanselAltinel · May 14, 2018 at 01:31 PM 0
Share

nope. but updating to Unity 2018 seems to have fixed this.

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

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

How to move BoxCollider2D 1 Answer

Unity 2d Physics Collision Jumping / Glitching 0 Answers

Platformer2D Player sticks to platform corners 0 Answers

Tile Generation with collider2D's 1 Answer

My player passes through walls on android build 0 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