Prevent rigidbody from sliding on another

Hi! I’m trying to make a simple mob for my game that carries a box on a tray. The tray is attached to the character, and the box is on top of the tray. The mob also has a rigidbody. I have a simple script that moves and rotates the mob using rigidbody.MovePosition() and rigidbody.MoveRotation(). The problem I’m running into is that the box will just slide right off of the tray no matter what I do. I know this is probably a really dumb question, but is there anyone who can help out?


In theory you can increase the friction, esp. for the tray, but I’ve never gotten that to really work. I think “for real” someone carrying a tray is tilting it a little “into” their motion, which is tricky to simulate.

You can “lock” a rigidbody by turning off physics and childing it: box.rigidbody.isKinematic=true; and box.parent=tray;. Then to set it free, turn off isKen and unchild it: box.parent=null;

If you want other things to be able to knock it off, you can check collisions, something like (tested, but not this exact code):

OnColEnter(Collision cc) {
  if(!cc.transform.CompareTag("player")) {  // hit by not the player
    if(cc.relativeVelocity>10) {  // ...with a decent amount of force
      // unchild and and isKen, so it moves freely again