Calcular impluso ou força corretos para mover um corpo do Box2D para uma posição específica - Box2D
Eu tenho uma pergunta sobre como mover um corpo Box2D para uma posição específica sem usar isso, por exemplo.
body->SetTransform(targetVector,body->GetAngle())
Eu tenho algum código que funciona para applyForce (aqui):
const float destinationControl = 0.3f;
b2Vec2 missilePosition = _physicalBody->GetPosition();
b2Vec2 diff = targetPosition - missilePosition;
float dist = diff.Length();
if (dist > 0)
{
// compute the aiming direction
b2Vec2 direction = b2Vec2(diff.x / dist, diff.y / dist);
// get the current missile velocity because we will apply a force to compensate this.
b2Vec2 currentVelocity = _physicalBody->GetLinearVelocity();
// the missile ideal velocity is the direction to the target multiplied by the max speed
b2Vec2 desireVelocity = b2Vec2(direction.x * maxSpeed, direction.y * maxSpeed);
// compensate the current missile velocity by the desired velocity, based on the control factor
b2Vec2 finalVelocity = control * (desireVelocity - currentVelocity);
// transform our velocity into an impulse (get rid of the time and mass factor)
float temp = (_physicalBody->GetMass() / normalDelta);
b2Vec2 finalForce = b2Vec2(finalVelocity.x * temp, finalVelocity.y * temp);
_physicalBody->ApplyForce(finalForce, _physicalBody->GetWorldCenter());
}
Mas quando omaxSpeed
é alto, o corpo se move sobre o ponto rapidamente.
Alguém sabe como calcular uma força (ApplyForce
) ou um impluso (ApplyLinearImpulse
) para mover o corpo para uma posição de destino (exatamente) em um horário específico.
Ou uma solução com o código acima. Quero dizer calcular omaxSpeed
para mover o corpo em um horário específico para a posição de destino.
Na minha pesquisa no google, encontrei o interessante artigo da iforce sobre a trajetória projetada (aqui) Talvez isso possa ajudar também?
Agradeço antecipadamente