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 Eco-Editor · Feb 08, 2017 at 04:10 PM · physicsrigidbodyobjectboxcolliderpick up object

Box collider on a moving object-shopping cart

Hello all,

Hope this is a new question: My goal in the scene is to have FPcharacter to pick a product and place in the cart. For that I've made all my "products" have box collider (for ray cast) and rigidbody (for behaving like in the real world). The cart also has box colliders, for the products to "stay" in the cart, 5 cubes with box colliders surrounding the cart (see picture) and made transparent for esthetic reasons.

Once I put the object in the cart it starts: 1. being all edgy and restless and jumpy like. 2. it doesn't stay there once the cart is moved, it slips away and falls. I've checked the colliders on the cart it's hermetically tight, no open "holes". I've tried playing with drag, mass, angular drag on Rigidbody.

How come the object is "falling" out of the cart?

Many thanks for your suggestions.

alt text

cartcollider.jpg (90.6 kB)
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 jmgek · Feb 09, 2017 at 03:46 PM 0
Share

I always tell people to stay away from any type of collision physics. Your going to have to add some logic to your shopping cart, you can't rely on physics to calculate the objects in your cart.

Your problem your having is there is too many calculations your trying to preform and the physics on the box collided is calculating verts outside thus, allowing things to push through your shopping cart collides. Even if you got it working perfectly on your machine there is no guarantee on a slower machine these same things won't happen.

You will most likely have to implement some sort of transform fix to hold your objects in your cart.

Take a look at how unity calculates collider physics and you will understand.

avatar image Eco-Editor jmgek · Feb 10, 2017 at 01:09 PM 0
Share

Hello jmgek,

When you say logic do you mean scripting? I've managed to make the product "sit" calmly in the cart. But it still falls. This happens because, while the cart rotates, left\right (the x axes), the product wouldn't move with it (like when you have a sharp turn with your car, and your body seem to go the opposite way?). When the product is a child object of the cart then it keeps in the cart, of course. So I have a dynamic interaction between the cart (which is now a rigidbody with box collider) and a product - rigidbody with box collider. Perhaps I should use something like AddForce? to add force to the product?
Still looking to find some good materials about how unity calculates collider physics....

avatar image jmgek Eco-Editor · Feb 10, 2017 at 05:35 PM 0
Share

Yes, you will have to add additional scripts to hold your objects in the cart. A quick fix is to just gameobject.transform.positon = shopingCartBox.position; Could I ask, whats the benefit to having object move once placed?

One way I can think of off the top of my head is to add a box collider inside the cart then use https://docs.unity3d.com/ScriptReference/$$anonymous$$onoBehaviour.OnCollisionExit.html On collision exit to add force once it's calculated when out of bounds.

3 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by AquaBomber · Feb 08, 2017 at 04:38 PM

Is your cart moving?If so you could do something like a "fake" product as a child of the cart with the product mesh.

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
avatar image
0

Answer by Eco-Editor · Mar 01, 2017 at 07:15 AM

Hi jmgek,

once placed, the object need not move. I think what the approach should be is that: there's a collider, at the top of the cart, and it has a script on it that looks for a rigidbody (as all the products has this component) and once the product is picked and is "thrown" into the cart, it goes through the collider, and "looses" it's rigidbody features to become a child object of the cart, as it lands on the bottom. OnCollisionExit is an option here? How would you approach this?

Thanks.

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
avatar image
0

Answer by AladdinHZ · Jun 30, 2017 at 08:49 PM

Hello @Eco-Editor, I'm facing the same issue what I've done is add Tag "CART" to the shopping cart, then attach script to the pick able object with the following:

Code :

void OnCollisionEnter(Collision col) {

     Debug.Log ("ProductHandler : " + col.gameObject.name);
     if (col != null) {
         if (col.gameObject.tag == "CART" ) {
             Debug.Log ("ProductHandler TAG : " + col.gameObject.tag);
             // ADD INSIDE CART REMOVE RIGIFBODY 
             // SET COLLIDING AS PARENT
             Rigidbody rg = GetComponent<Rigidbody>();
             if (rg) {
                 Destroy(rg);
             }
             transform.tag = "inCart";
             transform.SetParent (col.transform);
             this.enabled = false;
         }
     }
 }

so I remove the Rigidbody and set the cart as parent.

But I still have issue where my cart get through walls !!! Did u had this issue ?

Comment
Add comment · Show 1 · 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 Eco-Editor · Jul 01, 2017 at 05:50 PM 0
Share

Hi @AladdinHZ , I'm still trying to figure this out myself. One solution is to have a bigger character controller radius that will involve the cart, but it has it's downs.

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

8 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

swapping out an object on collision 2 Answers

Why do I get OnTriggerExit upon collision when a rigidbody is kinematic? (example) 3 Answers

Character with box collider sticks to walls 0 Answers

Apply Gravity to Car Physics 0 Answers

Collision Detection for Kinematic Rigidbodies 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