This project has moved. For the latest updates, please go here.

Get Forces Acting on a Body

May 6, 2011 at 6:28 PM
Edited May 6, 2011 at 6:38 PM

Hello! I've got a body, and I need to apply an upwards force to it appropriate to all the downwards forces acting on it.

Best way to describe it is like a lift, I guess - no matter how many elephants and cars are on the 'lift' it always moves upwards at the same speed. Even if there's nothing on it. Or if there's a single feather on it. Whatever.



private void moveLiftUp()
   float _f = getForcesActingOnLift();

   // apply a force that moves the lift upwards
    _fixture.Body.ApplyLinearImpulse(new Vector2(0, _f + 1));


FULL DISCLOSURE: I'm simplifying here. It's not just a lift, but that's the best way I can describe the problem easily. What I'm saying it I can't use a Kinematic body/ path combo ;)


Any suggestions would be much appreciated :)

May 6, 2011 at 7:52 PM
Edited May 6, 2011 at 7:54 PM

Perhaps if you just zero the Y component of Body.Force and apply a mass-relative upward force just before it reaches the solver it will do what you need? You'd need to hook in at the right time anyway to be sure nothing else was messing with the force accumulator.

May 7, 2011 at 9:23 AM

Aaaah, that's quite clever, thanks. I'll look into it.

I've stumbled on another workaround which also seems to be working - that being to apply an appropriate force based on velocity. Result being no matter how heavy the cargo, the lift should always move up.

private void moveLiftUp()
   if (_fixture.Body.LinearVelocity.Y < fDesiredVelocity) { fAppliedForce++; }

    // apply a force that moves the lift upwards
     _fixture.Body.ApplyLinearImpulse(new Vector2(0, fAppliedForce));