Search Unity

A center of gravity that suffers inertial forces

Discussion in 'Scripting' started by odival, Jun 1, 2016.

  1. odival

    odival

    Joined:
    Jun 11, 2014
    Posts:
    57
    Hello, I need help and advice on how to script a behavior for a gameobject (child) that acts as center of gravity for another gameobject (parent). The catch is that this center of gravity should respond to inertial forces, much like in the crude example pic bellow:

    EDIT: In a second thought, this pic doesn't do justice to what I want to describe. Imagine there's a ball inside your car and that ball is attached by a short rubber band to the center of the car. As you accelerate, brake and turn the ball will roll according to inertia, and them go back to it's origin as soon as the inertial forces dissipate. That's kind of what I want to simulate.

    As you can see the center of gravity moves slightly in almost the oposite direction of the direction its parent is moving. Since the parent is moved by applying forces to its rigidbody, how can I make the child center of gravity respond accordingly, in a reallistic manner?
     
    Last edited: Jun 1, 2016
  2. lordofduct

    lordofduct

    Joined:
    Oct 3, 2011
    Posts:
    8,532
    Attach a second rigidbody (child) to the first rigidbody (parent) with a spring joint?
     
    odival likes this.
  3. odival

    odival

    Joined:
    Jun 11, 2014
    Posts:
    57
    Gosh, do I feel stupid now. I totally forgot about spring joints. To be honest I never used them before and that's why I couldn't remember about them. Anyway, I did exactly what you told, and it seems to be working perfectly!
    Thanks a lot! =D
     
    Last edited: Jun 2, 2016