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 /
  • Help Room /
avatar image
0
Question by dutchtim2003 · Mar 02, 2021 at 12:04 PM · collisioncollider2d2d-physicscollision2dsimulation

2d balls stuck in box colliders

In this simulation, an x amount of little balls are spawned into a 2d rectangle surrounded by walls. These all follow a randomly selected movement direction. After a few minutes is allotted they all somehow end up stuck in the corners (see screenshot).

I can't find the solution. I have tried a lot from changing the physical material to trying to reverse the movement on entering the walls. The walls are also set to static and the balls are set to dynamic.

 ![void Start()
     {
         InvokeRepeating("ChangeDirection", 0, 1f);
         nog_gezond = true;
     }
 
     // Update is called once per frame
     void Update()
     {
         transform.Translate(direction * Time.deltaTime, Space.World);
 
     }
     void ChangeDirection()
     {
         angle = Random.Range(0.0f, 360.0f);
         steps = Random.Range(0.1f, 2.0f);
         direction.x = steps * Mathf.Cos(angle * Mathf.Deg2Rad);
         direction.y = steps * Mathf.Sin(angle * Mathf.Deg2Rad);
     }
     void OnTriggerEnter2D(Collider2D other)
     {
         if (other.gameObject.CompareTag("Infected") && nog_gezond == true)
         {
             kans = Random.Range(1, 100);
             if (kans <= besmetting_kans)
             {
                 transform.gameObject.tag = "Infected";
                 gameObject.GetComponent<Renderer>().material.color = new Color(1.0f, 0, 0);
                 counter.healthy -= 1;
                 counter.infected += 1;
                 InvokeRepeating("add_days", 0, 1);
                 nog_gezond = false;
             }
         }
         if (other.gameObject.CompareTag("GameController"))
         {
             transform.Translate(direction * Time.deltaTime * -1, Space.World);
         }][1]


[1]: /storage/temp/176815-screenshot-2021-03-01-at-204328.png

screenshot-2021-03-01-at-204328.png (67.2 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 tylerdtrudeau · Mar 05, 2021 at 12:49 AM

I've experienced something like this before. Do you have the physics material bouncy set to max (1)? Secondly depending on how you have the rigidbody set up on the balls then during the collisions they can start to lose velocity, slow down, and eventually stop. You can write a couple lines of script that ensures a constant velocity (something like Vector2.Reflect) and then they will never slow down or stop.


This post helped me alot, so much so I still had it bookmarked.


https://stackoverflow.com/questions/65788949/how-to-keep-the-same-velocity-after-bumping-into-things-unity-2d


Cheers

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

228 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image 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 fix strange 2D colliders behavior? 0 Answers

Why Object2D jump out collision? 1 Answer

Circle Collider2D Stuck ob Box Collider2D at the corner :( 0 Answers

Tilemap Collider problems 0 Answers

How to check if any/multiple 2D sprites neighbour/collide with eachother 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