Search Unity

Make a Rigidbody affected by a weight hanging under it?

Discussion in 'Physics' started by Sunexo, Jun 17, 2019.

  1. Sunexo

    Sunexo

    Joined:
    Jun 14, 2015
    Posts:
    9
    Good evening! I've hit a bit of a snag, the easiest way to describe what I am after is to liken it to the following: you have a helicopter carrying a heavy cargo beneath it suspended from a cable. As you maneuver the helicopter the weight under it swings due to its inertia or external forces such as wind. This results in that weight suspended below the helicopter "tugging" on the helicopter. That "tugging" results in a change in position for the helicopter. At the moment I have a character controller that consists of a Rigidbody that is moved by the player through AddForce and a "cable" that consists of a series of joints that can attach itself to another Rigidbody. The cargo Rigidbody swings about as you maneuver the player Rigidbody but of course there is none of the desired affect on the player Rigidbody. Been digging into the issue for a while and can't seem to find anything that has been helpful in this particular situation. Any help would be greatly appreciated!
     
  2. Maeslezo

    Maeslezo

    Joined:
    Jun 16, 2015
    Posts:
    332
    Hi!

    I sounds like a real physic effect. If you affect the cargo with a force, it will affect the helicopter thorough the joints.
    I understand that this could be a problem for the gameplay. What you could do is to connect the cargo to a kinematic rigidbody, and place this kinematic rigidbody to the helicopter hierarchy.
    This way, the cargo with follow the helicopter, it will have the cable behavior and the helicopter won't be affected
     
  3. Sunexo

    Sunexo

    Joined:
    Jun 14, 2015
    Posts:
    9
    Hey, thanks for the quick response! I'm sorry I should have been a bit more specific in my post. I WANT the player to feel the affects of having cargo swinging below them. Getting the player rigidbody to respond to the cargo rigidbody like it would in real life is where I'm stumped.
     
  4. Maeslezo

    Maeslezo

    Joined:
    Jun 16, 2015
    Posts:
    332
    Ah ok!
    Really? I doesn't affect? That's weird! If they are connected by joints, it should affect. I have done a test with two rb connected by a joint and the effect is the expected.
    What is the mass of the helicopter and the cargo? Maybe the cargo mass is too small to affect the helicopter.

    There are 3 things that you can check:
    - Connected Anchor: This is where the cable is connected. If it is connected to the helicopter center of mass , the effect will be lower because it won't generate torque. Be sure that the cable is connected to the bottom of the helicopter.
    - Mass of the cargo. It should be enough to affect the helicopter.
    - There is a parameter in the joints, massScale (https://docs.unity3d.com/ScriptReference/Joint-massScale.html) It is usually used for this kind of things, maybe it could be helpful.
     
    Edy and SparrowGS like this.
  5. Sunexo

    Sunexo

    Joined:
    Jun 14, 2015
    Posts:
    9
    I'll check my setup, sounds like I've probably botched a setting somewhere, thank you!
     
  6. Sunexo

    Sunexo

    Joined:
    Jun 14, 2015
    Posts:
    9
    Turns out the code was just pinning the first joint to the player transform instead of having the player rigidbody set as the connected rigidbody within the joint. Completely overlooked it and overcomplicated my search for a solution! Thanks for the feedback Maeslezo, got me back on the right track!
     
    Maeslezo likes this.