- Home /
One-way bounciness
I'm developing 2D platform game. Using 2d box colliders & rigid bodies I have three kinds of objects:
a Character
a Crate
a Platform
Since I don't want Character to bounce off the Platform, but to stick to it, I set up both of their PhysicsMaterials to have Bounciness == 0. However I do want my Crate to bounce off the Platform when it falls from high enough, thus I decided to set its Bounciness to 0.2 (for now). The problem is that my Character bouncess off the Crate too now, which is undesirable.
It wouldn't be much of an issue, because it's hardly noticable at all... However it causes the falling animation for the Character launch several times. The trigger on the mecanim Animator that fires the animation is a bool parameter IsFalling, which I set to true, whenever Character's rigidbody's vertical velocity is lower than -0.001 (I had to put some threshold to avoid float precision causing my animation to fire).
It looks quite bad and I thought it's the best to address the root cause of the problem - my Character shouldn't bounce off the Crate at all. However from my research it seems that bounciness parameter of the Physics material always works two way and selects the net bounciness of any two objects following the maximum rule - the bigger one will be the bounciness for both of them. Unless there is a way to set this up somehow, of which I'm not aware?
The only thing I can think of now is just zeroing the vertical velocity of a Character once it lands on anything, but it looks like a bit of an workaround instead of addressing the real problem...
Answer by Bunny83 · May 22, 2018 at 12:16 AM
Well, unfortunately the 2d physics material doesn't have the combine options that the 3d physics material has. However the overall concept of having different results for the same collision is actually not physically correct. A collision is either elastic, inelastic or something in between. Therefore the result would correctly apply to both participants of a collision. So it seems that you can't get the 2d physics system to do that unrealstic behaviour you want. So zeroing the vertical velocity on collision might be the best solution.
Yeah... I figured this much after more thought... I ended up doing quite a crazy workaround with cases when should the vertical velocity be zeroed (it depends on whether it's really falling or not, or perhaps just started falling, or if it has just jumped or not; it also has a special case when the Character is not quite falling but it's on a steep slope and tries moving upwards (as it shouldn't be able to do so too)). The code behind is pretty complicated and I'm so not proud of it, but it's contained in one class that doesn't affect anything else, so at least it won't make mess in other parts. Encapsulation ftw. As for the link you provided, I already found somewhere that for 2D friction multiplies and bounciness get's the max. But it's nice to have it pictured like in that answer.
Your answer
![](https://koobas.hobune.stream/wayback/20220612163141im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Hold to jump higher 0 Answers
Mobile platformer jump not working 2D 1 Answer
2d character horizontal movement 1 Answer
2D platformer landing problem? 1 Answer