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.

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

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.

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 ?

Hi! I know some time has passed, but I was wondering if you have solved everything? If yes, I would like to ask for a little help on how to create a shopping cart with its corresponding logic implemented, so that the objects stay inside. Thank you!