Search Unity

Retrieve force vector applied by physics engine.

Discussion in 'Physics' started by JohnHubner, Jun 11, 2018.

  1. JohnHubner

    JohnHubner

    Joined:
    Dec 29, 2015
    Posts:
    4
    Is there a method that supplies the force vector being applied to a 3D rigidbody by the physics engine when its simulating inertia? Or, would I need to calculate that myself?

    I don't see anything like that in the docs, but I could be blind.
     
  2. dgoyette

    dgoyette

    Joined:
    Jul 1, 2016
    Posts:
    4,196
    You won't be able to get that. Things you have available to you:
    • The Velocity Vector3 property, which tells you how fast and in what direction the object is moving. This will be net of all forces acting on the body, but you could potentially track this over time and reverse engineer the net force between physics updates.
    • For collisions, the collision object has an Impulse property which tells you you the force of the collision. This is useful for knowing how "hard" a collision was, as it takes the object masses into account (versus the relativeVelocity property).
     
  3. AlanMattano

    AlanMattano

    Joined:
    Aug 22, 2013
    Posts:
    1,501
    I do not understand the question. Are you trying to get the sum of gravity vector + deceleration (or acceleration) vector?
     
  4. JohnHubner

    JohnHubner

    Joined:
    Dec 29, 2015
    Posts:
    4
    Thanks. I figured I'd have to calculate it myself from Velocity, I was just really hoping i was wrong.
     
  5. JohnHubner

    JohnHubner

    Joined:
    Dec 29, 2015
    Posts:
    4
    No, I'm assuming that the physics engine is internally calculating a force vector to apply to the rigidbody that simulates the rigidbody's "inertia" while it's in motion. I was hoping to be able to get this directly, rather than having to calculate it from the body's Velocity and mass.
     
  6. dgoyette

    dgoyette

    Joined:
    Jul 1, 2016
    Posts:
    4,196
    I doubt it works like that. Inertia isn't a force, it's the default state of an object. Forces may act on an object to slow its velocity over time, but the physics engine isn't adding forces to object to keep them moving on their existing path. The object will keep moving until something (gravity, collision, explosive force, drag, etc) causes it to change velocity.

    Do you want to say why you think you need this "inertia" force? Like, what do you expect to do with that information?
     
    JohnHubner likes this.
  7. JohnHubner

    JohnHubner

    Joined:
    Dec 29, 2015
    Posts:
    4
    Good point. If the physics engine works anything like reality, it was a really bad assumption. I was definitely coming at my problem from the wrong end. I had already decided what I wanted to be the answer, and allowed it to affect my perception of the problem. Newton would probably slap me.

    The reason I was looking for that figure is simply because I like to experiment with creating different types of flight models using various available feedback mechanisms as input for controlling flight characteristics. If there was a simple force vector figure that simulated inertia, it would be less work for me in my current experiment. But, that's what laziness will get you, sloppy thinking.

    It's clear that I'll have to do the legwork and use my own calculations, so I think we can consider this thread usefully answered. Thanks for nudging me back in the right direction.