Search Unity

Resolved Rigidbody's "use gravity" option automatically turns itself on

Discussion in 'Physics' started by TheHowYou, Jan 16, 2022.

  1. TheHowYou

    TheHowYou

    Joined:
    Nov 18, 2021
    Posts:
    3
    As the title says, I have rigidbodies which I do not want to be affected by gravity.

    I have the "use gravity" checkbox unchecked on them at start. However, they will automatically start using gravity once another rigidbody interacts with them or just gets close enough to them (just my observations).

    I do want gravity though (on other rigidbodies)... so simply setting gravity to 0 is not an option.

    I do not want to make them kinematic as I do want them to interact with other rigidbodies.

    My current solution is to just simply set "use gravity" to false every time the code runs through FixedUpdate:
    _rigidbody.useGravity = false;


    This is a little less than ideal. So I'm hoping someone could shed some light on this. I'm not one to ask for help often, but I've done some searching and didn't find much... and this is more of an annoyance than an actual problem at this point.

    Thanks in advance!
     
  2. Edy

    Edy

    Joined:
    Jun 3, 2010
    Posts:
    2,510
    Never seen that behavior in Rigidbodies. Some other script in your project is turning "Use Gravity" on. Try searching for ".useGravity" across all the source code files in your project.
     
  3. TheHowYou

    TheHowYou

    Joined:
    Nov 18, 2021
    Posts:
    3
    As soon as I read Edy's post above, I knew what was causing it. Come to think of it, I have never experienced this behavior before either. Thanks for taking the time to point me in the right direction. Much appreciated.

    A while ago I was having some fun and crudely introduced a sort of "tractor beam/vacuum weapon" on my player which I affectionately dubbed "Sucker Upper". It has a trigger that disables and enables gravity on any affected rigidbodies (and does not honor the original state) which is causing my issue. Completely forgot about it since it was done on a whim.

    This was not an issue until recently when I just duplicated my playable character and was experimenting with switching players and controls to different playable characters and controls on the fly. My playable characters use a custom implementation of gravity... which everything I use will probably do since it's going to be a complicated universe, but for now it's nice to have this issue I created figured out.

    Thanks again to Edy.
     
    Edy likes this.