我的物理引擎中有一个碰撞解决方法,就像这样:
Vector2 n1pos = n1.NonLinearSpace != null ? n1.NonLinearPosition : n1.Position;
Vector2 n2pos = n2.NonLinearSpace != null ? n2.NonLinearPosition : n2.Position;
Vector2 posDiff = n2pos - n1pos;
Vector2 posDiffNormal = posDiff;
posDiffNormal.Normalize();
float totalRadius = n1.Radius + n2.Radius;
float posDiffLength = posDiff.Length();
float interPenetration = totalRadius - posDiffLength;
float averageRestitution = (n1.RestitutionCoefficient + n2.RestitutionCoefficient) / 2;
Vector2 forceAmount = Vector2.Multiply(posDiffNormal, interPenetration);
Vector2 n1force =
(
(n1.Velocity * n1.Mass) +
(n2.Velocity * n2.Mass) +
n2.Mass * averageRestitution * (n2.Velocity - n1.Velocity)
) /
(n1.Mass + n2.Mass);
Vector2 n2force =
(
(n1.Velocity * n1.Mass) +
(n2.Velocity * n2.Mass) +
n1.Mass * averageRestitution * (n2.Velocity - n1.Velocity)
) /
(n1.Mass + n2.Mass);
n1.ApplyForce(???);
if (!n1.IsStatic)
{
n1.Position += ???;
}
n2.ApplyForce(???);
if (!n2.IsStatic)
{
n2.Position += ???;
}
现在,我无法弄清楚应该对我的引擎中的物体应用什么来获得适当的恢复系数。 (???部分)。有人可以帮忙吗?
答案 0 :(得分:6)
根据这个和你的其他问题判断,你试图在行走之前跑步。
答案 1 :(得分:5)