So, i have 2 gameobject first one is truck and second one is bucket, so bucket and truck contains rigidbody. Because i use rigidbody velocity to move truck and bucket seperately. When i move truck to forward then the bucket is not moving with the truck in spite of both have the same parent.
Consider the use of some kinda of Joint.
but if i use joint, i will not able to control movement of the each of gameobject seperatelly
You have two options. Choose which one you like better.
First, connect the objects in some way, disable physics on the transported object while it’s being transported, and re-enable and disconnect them accordingly when taking it off your truck. This is somewhat easy to do in various ways, including parenting, joints, …but can potentially look weird in unusual situations, like flipping upside down in an accident. You could always just handle these cases separately tho. Overall the easy solution.
Secondly you could try to keep them as two separate objects at all times. For this you would have to literally apply the same force to the bucket as you do to the truck, and then probably some to make it appear natural. Or just run it as a full physics simulation, only relying on rigidbodies and collisions. Extremely complex and hard to do right.
That’s it. I cant think of anything else. Most go for #1. In the end it depends on the type of game and what’s really necessary to do in regards to that.
Thanks
Wait, shouldn’t friction do it’s job in your 2nd case?
I’m probably not the best person to go in-depth on this topic, as i only did a few experiements with physics-only behavior. For a full physics simulation you are probably right, friction should do the trick. In my reply i did not assume that the game is going to be a full physics simulation tho, as most games are not. For example, if it was a requirement that the bucket cant possibly fall of the truck. Or, say, the car can jump. Im not sure how the items on the truck would behave, but i dont feel like relying on physics only in these requirements would be the best choice. I should have clarified what i was imagining however, so sorry for the confusion.
I’m not saying your ideas were wrong, it’s just you omitted the friction, and I’m kind of imagining the bucket to completely slide off, which is not supposed to work like that.
In the real world, bucket in a truck is not actually tied to anything, and given a sufficient acceleration, will fly to the back as expected due to conservation of momentum. The only thing that actually makes it behave naturally is its own weight, and the forces of friction. And then I’m thinking “wait all Unity physics engines support friction just fine” hence the confusion.
That said, this scenario should be working out of box, unless mass, forces, dimensions, or colliders are completely wrongly set up.
I don’t mind your technical notions of approximating or emulating the result btw. That’s something that comes with the territory, but shouldn’t be the only way to solve this: i.e. this should work in the most basic scenario as it is.
@OP have you set up the so-called Physic material correctly? There are also several different physics computation models you can check out to refine certain interactions. Bucket-in-a-truck must work. In fact, a-barrel-and-a-dozen-crates-with-a-breakable-jug-in-a-moving-jumping-truck must work. That’s like the textbook example of physics capabilities.