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 mikembley · Jan 05, 2016 at 02:18 PM · triggerphysics2dcollider2d

Update scaling and 2d collider/trigger not firing

I have a snowball object that has a 2d rigidbody with a circle collider on it.

When the snowball travels it grows using scale

 //Used on LateUpdate() in SnowBall
 float travelDist = Vector2.Distance(transform.position, m_lastPosition);
         
 if (m_curBallSize < EndSize && travelDist > 0.01f)
 {
     m_grownSize += travelDistDelta / 10000f;
     SetBallSize(m_curBallSize + m_growSize);
 
     m_lastPosition = transform.position;
 }
 
 public void SetBallSize(float ballsize)
 {
     m_curBallSize = ballsize;
     transform.localScale = Vector3.one * ballsize;
 }

Now the problem occurs when the ball enters a scorezone, the scorezone has a 2d trigger which is used to reset the snowball, but unfortunately it just doesn't fire:

 //Code used with ScoreZone
 void OnTriggerEnter2D(Collider2D other)
 {
     if (scoreManager)
     {
         //All balls inherit NormalBall class
         NormalBall b = other.transform.GetComponent<NormalBall>();
 
         if (b)
         {
             Debug.Log(b.name + " hit goal, resetting it");
 
             //Process scoring
             scoreManager.AddPoints(Player, b.scorePointValue);
             b.BallScored(this);
             TheScore.Instance.Score += 12;
 
             //Reset afterwards
             destroyObject = b.gameObject;
             Invoke("LateDestroy", 0f);
         }
     }
 }

When I remove the scaling portion from SetBallSize(); then the trigger works fine and the ball is reset.

Edit: I should mention that the SnowBall inherits NormalBall, which absolutely works fine with the trigger, leading me to believe it is definitely the scaling screwing something up.

Is there a bug or an issue with scaling a 2d rigidbody/collider against a 2d trigger? Or is it just a thing that isn't supported?

Im a bit confused by this.

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 StaNov · Jan 05, 2016 at 02:32 PM 1
Share

$$anonymous$$aybe the scaling causes entering the ball into the trigger, so OnTriggerEnter2D is not fired.

Try to change it to OnTriggerStay2D.

But it's just a quick guess, so I might be wrong.

avatar image Leuthil · Jan 05, 2016 at 05:47 PM 0
Share

I don't see any reason it shouldn't work. Scaling should also scale the CircleCollider2D so everything should work properly. Odd that it works when you disabling the actual scaling. Perhaps you should try to make sure that the collider isn't missing the trigger on the Z axis (even though technically it should be more likely to hit since you are scaling the Z axis bigger as well). It could be something weird like getting a negative scale which might look visually ok if you just have a white ball but the collisions might get screwed up. Pause the game when it gets into the scorezone and see if the two colliders are actually inside each other and make sure you do not have any negative scaling.

1 Reply

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by Naphier · Jan 05, 2016 at 06:04 PM

I had a similar issue with our last game. We'd scale a gem to make it look like it was shrinking as it got near the center of the goal and sometimes the scaling would mess up the physics, sometimes the triggers. I think the issue may lie in the physics engine not recalculating the collision detection areas as quickly as we'd like it to. I ended up using a combination of continuous detection on the rb as well as OnTriggerStay. The OnTriggerStay gets called many more times than on enter. So I just had to add logic to the gem's class to record whether the trigger event had been called on it or not (also modifying it when it leaves), Hope this helps!

Comment
Add comment · Show 2 · 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 mikembley · Jan 06, 2016 at 01:09 PM 0
Share

I switched OnTriggerEnter for OnTriggerStay for testing purposes and it worked as normal.

I do believe it is a bug with the 2d trigger/physics system, but due to the way i'm using the trigger there are no ill effects since i am just using it as a fireonce trigger.

shrug

avatar image StaNov mikembley · Jan 06, 2016 at 01:21 PM 1
Share

I was glad to help :)

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

37 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

Related Questions

Moving many 2D triggers is slow. Why? 1 Answer

How to make a trigger still collides with specifc object? ,How to make a trigger stillcollide with specific objects? 1 Answer

OnTriggerExit2D Does not work 1 Answer

Physics2D.OverlapCircle dont detect triggers 3 Answers

Collision with instantiated non-moving objects. 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