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 bhavinbhai2707 · May 10, 2018 at 09:02 AM · 2d gamecolliderscollider2d

Ball getting stuck between two box colliders

I am making a puzzle game where the player has the objective of taking the ball into lower pipe. He can do this by moving the whole row or whole column alternatively every turn respectively.

But i am facing this weird issue where the ball gets stuck between two Box colliders while making a move (As you can see in the GIF Image) alt text

This blue ball is using circle collider 2D and a rigidbody2D The boxes consist of boxcollider2D and surface Effector 2D(Since i want ball to move automatically when there is space in front)

I seriously don't know how to solve this issue, i have searched forum for solution but i got no luck with those solutions!!

I will be really glad if someone can help me with this issue :) !!

Edit 2: Here is the small piece of code that handles the boxes as requested by @tormentoarmagedoom , it is kind of hard to explain code since it is very large algorithm consisting of many scripts, but i will try my best to explain!!

I am using MVC structure(Model view controller). The boxes in the gif image are just for purposes of display and the movement you see is controlled by a script i.e, the model. The boxes are represented as a 2D array form and all the controlling of 2D array which is not seen by user is done by other script in background i.e, the controller. the controller is managing the 2D Array.

  public void boxRCSwap(GameObject selectedObj, bool X,bool right,bool up)
     {
             GameObject target = null;
             int[] p = findElementPositionInArray(selectedObj);                                     //This function is finding the array position of box the player touched
         if (selectedObj != null)
         {
             if (X)
             {
                 for (int i = 0; i < columns; i++)
                 {
                     target = boxes[p[0], i];
                     if (target != null)
                     {
                         waitTime = 0;
                         if (right)
                             StartCoroutine(Transition(target, (target.transform.position.x + constNumberX), p, true));                       
                         else if (!right)
                             StartCoroutine(Transition(target, (target.transform.position.x - constNumberX), p, true));
                     }
                 }
             }
             else
             {
                 for (int i = 0; i < rows; i++)
                 {
                     target = boxes[i, p[1]];
                     if (target != null)
                     {
                         waitTime = 0;
                         PlayerMechanics.movesCounter();
                         if (up)
                             StartCoroutine(Transition(target, (target.transform.position.y + constNumberY), p, false));
                         else if (!up)
                             StartCoroutine(Transition(target, (target.transform.position.y - constNumberY), p, false));
                     }
                 }
             }
             reArrangeArray(X, p, right, up);                                 //This function is rearranging the 2D Array according to changes player made
         }
         
     }


Basically i am lerping the boxes in order to move them from one position to other for example box[0,0] moving to box[0,1]

 private IEnumerator Transition(GameObject target, float X, int[] p,bool xAxis)
     {
         while (waitTime < waitForSeconds)
         {
             if (xAxis)
             {
                 target.transform.position = Vector2.Lerp(target.transform.position, new Vector2(X, target.transform.position.y), (waitTime / waitForSeconds));
             }
             else
             {
                 target.transform.position = Vector2.Lerp(target.transform.position, new Vector2(target.transform.position.x, X), (waitTime / waitForSeconds));
             }
             waitTime += Time.deltaTime;
             //   yield return new WaitForSeconds(0.1f);
             yield return null;
         }
     }

This is inspector of ball and the crates as requested by @TanselAltinel

inspector of crate Click here

Inspector of ball Click here

Note :- Ballbehaviour script is doing nothing but checking axis of y if it's dropped in that acid or not!!

ezgifcom-gif-maker.gif (386.1 kB)
Comment
Add comment · Show 6
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 TanselAltinel · May 10, 2018 at 09:21 AM 0
Share

Can you please show editor inspector for ball and crates?

avatar image tormentoarmagedoom TanselAltinel · May 10, 2018 at 09:24 AM 0
Share

Yes, and can you post how the boxes are moved in the code? They are $$anonymous$$inematic? $$anonymous$$oved by forces..?

Thanks.

avatar image bhavinbhai2707 · May 10, 2018 at 09:55 AM 0
Share

@TanselAltinel @tormentoarmagedoom i updated the post, please check it :) !!

avatar image TanselAltinel bhavinbhai2707 · May 10, 2018 at 10:11 AM 0
Share

You're moving objects with updating transform values, which confuses physics engine. I think that's the problem.

avatar image bhavinbhai2707 TanselAltinel · May 10, 2018 at 11:01 AM 0
Share

So what should be possible solution for that??

Show more comments

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

94 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

Related Questions

Moving an object with a collider in 2d? 1 Answer

Why is there a gap between my player and the wall during wall slide? SOLVED 2 Answers

How to destroy player when collide with enemy? 3 Answers

Problem with method Collider2D.isTouchingLayers() 4 Answers

Collider lets object through 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