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

Need help with counter gravity

Discussion in 'Physics' started by Reaven99, Feb 17, 2016.

  1. Reaven99

    Reaven99

    Joined:
    Oct 3, 2015
    Posts:
    39
    Hello,

    I am having trouble making some sort of "hover" rigidbody.

    I have a couple of rigidbodies with different mass connected to eachother with a "fixed" joint.
    1 of those rigidbodies will have a script that whould make them all hover [because they are connected]
    But somehow i cannot figure out the neccesary math to make them hover.

    I have tried both:
    RB.AddForce(-Physics.gravity*6f,ForceMode.Acceleration);
    RB.AddForce(-RB.velocity,ForceMode.VelocityChange);

    But they wont hover it perfectly, and that is because there are other bodies connected to the hover body.

    I cannot loop through them to get all the connected mass needed as those bodies can get destroyed at runtime, and it would hit the performance aswell.

    Thank you in advance.

    Regards
     
  2. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    10,372
    Fab4 likes this.
  3. Reaven99

    Reaven99

    Joined:
    Oct 3, 2015
    Posts:
    39
    Thank you for the reply, but the connected bodies still have gravity so it won't work.
    And setting them all off requires me to loop through them which is also not an option im afraid..
     
  4. Ahlywog

    Ahlywog

    Joined:
    Oct 24, 2014
    Posts:
    30
    Instead of countering gravity maybe try to counter the rigidbody velocity?
     
  5. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    10,372
    I'm confused. Each one will have gravity applied so how to you expect to counter gravity by only applying it to one without knowledge of the others effects on it.