In Box2d v2.?, I was using the function
to move my character horizontally. It allowed for some sliding, unlike simply setting the velocity directly, and avoided the problems of a fixed force + velocity damper style solution.
Unfortunately, under the release I'm using (Box2D.XNA r31) my character's velocity is oscillating back and forth around the desired value. My suspicion is that "acceleration = (desiredVel - vel) / dt" no longer matches the internal velocity calculation. That or I'm making some huge sign error somewhere.
Any suggestions on ways to avoid this problem?
Code:
float GetAcceleration(float vel, float desiredVel, float dt)
{
float a = (desiredVel - vel) / dt;
if (a < -_maxAcceleration)
a = -_maxAcceleration;
else if (a > _maxAcceleration)
a = _maxAcceleration;
return a;
}
{
float a = (desiredVel - vel) / dt;
if (a < -_maxAcceleration)
a = -_maxAcceleration;
else if (a > _maxAcceleration)
a = _maxAcceleration;
return a;
}
to move my character horizontally. It allowed for some sliding, unlike simply setting the velocity directly, and avoided the problems of a fixed force + velocity damper style solution.
Unfortunately, under the release I'm using (Box2D.XNA r31) my character's velocity is oscillating back and forth around the desired value. My suspicion is that "acceleration = (desiredVel - vel) / dt" no longer matches the internal velocity calculation. That or I'm making some huge sign error somewhere.
Any suggestions on ways to avoid this problem?