- Home /
Move 2 rigidbodies together, but allow one to slide off
Sorry for the bad title, I couldn't think of a better way to word it.
I am developing a 2D platformer, which allows the player to take turns controlling different Gameobjects. One of the mechanics is that the player should be able to make one of the objects jump onto another, and when the player is controlling the object on the bottom, the one on top should follow.
I have found several different ways to achieve this, however, none of which allow the player on top to slide off, if the object on top hits an object that the object on the bottom is passing under. Instead, they both just stop.
The objects can't be parented to each other, as Rigidbodies act incorrectly. I have tried different joints, but could not find a suitable one.
Sorry again if the wording is poor, it is hard to describe correctly. The best example I can give is how the characters act in Thomas Was Alone.
Any help would be greatly appreciated.
Answer by jimmycrazyskills · Dec 19, 2018 at 06:29 PM
I don't know if it would work, but could you calculate which object was on top then if that collides with something and the bottom one doesn't, could you use a physics material with low friction to allow the top object to slide over the bottom one maybe.
Hope this helped a little :)
Thanks, this helped a lot. I can't believe I didn't think of that, I think I was over complicating it. I basically ended up adding a physics material with really high friction, and use OnCollisionEnter to check if the top object hit a wall. If they hit a wall, then I'd swap the material for one that had low friction. Finally I used OnCollisionExit to check if the top object was leaving the wall, and if they were, I'd reapply the high friction physics material.
Thanks again.