Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Question How to prevent rigidbody object from being easily pushed over

Discussion in 'Physics' started by x8c8r, Aug 13, 2023.

  1. x8c8r

    x8c8r

    Joined:
    May 2, 2021
    Posts:
    2
    I have this object in my game, it's a cube. Currently the player can just easily flip it on the other side by just slamming into it's upper part, as well as just ram into it and push it around (both cube and player use rigidbody). I want to prevent this sort of behaviour, but also not increasing mass too much, since I don't want the cube to fall too fast when affected by gravity, and also I want it to be easily pushed by the cubes of same type (kind of like dominos but not really).

    I probably overconvoluted my explanation, so basically. I wanted the cube to not be easily pushable by the player, but be easily pushed by other cubes and the environment.
     
  2. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    10,468
    Lower its center of mass.
     
  3. karliss_coldwild

    karliss_coldwild

    Joined:
    Oct 1, 2020
    Posts:
    530
    You can also completely prevent rotation around some or all axis by using "Freeze rotation" under rigid body constraints. But it will depend on the game you are making whether that's a suitable solution.

    One more factor that can influence how easy it is to push over an object is friction. With lower friction it's more likely to slide instead of fall when pushed."

    One thing to watch out with center of mass offsetting approach is that you are offsetting it in some direction. It will be lower only while the object is standing upwards. But if you do manage object to flip, the offset center of mass will have opposite effect, it will make it easier to flip again. Depending on the style of game and whether the object has clearly defined upwards direction this may be the thing you want or it can be very bad. If you want object to behave like those wobbly self up righting toys offseting center of mass is a good solution, that's exactly how they work in real life as well.
    If you want object to resist falling over, but remain on the new rotation once you managed to flip it, offseting center of mass is not the right solution. If you have something like a cube which looks identical from all sides and game permits it to roll, having it roll with offset center of mass will look very weird.
     
  4. x8c8r

    x8c8r

    Joined:
    May 2, 2021
    Posts:
    2
    Freezing rotation is probably not the case. I should mention that the cube is not really a cube, and more of a cuboid, with a more stretched out length.

    I tried to change the center of mass. But it ultimately failed. I put it at the bottom of the cube, but that didn't prevent it from falling over easily, even worse, it now rolls after being pushed instead of just falling over once.

    EDIT: My solution might actually just be mass all along, since, if cubes have the same mass they can push each other (only on high speeds tho, which is still not really what I need). I still don't know about gravity tho.

    EDIT 2: Gravity actually doesn't seem too bad!

    EDIT 3: Okay, I tweaked some things. Added a frictionless phys material and now cubes push each other well. Player can still very easily push over a cube with enough speed tho.
     
    Last edited: Aug 13, 2023