C# 不分离物体的脉冲分辨率

C# 不分离物体的脉冲分辨率,c#,physics,collision,C#,Physics,Collision,当我正在处理的项目中的两个对象之间发生碰撞时,我运行以下代码: Vector2 relativeVelocity = entity.Velocity - this.Velocity; Vector2 normal = Vector2.Normalize (relativeVelocity); float normalVelocity = Vector2.Dot (relativeVelocity, normal); float restitution = Math.Min(this.Restit

当我正在处理的项目中的两个对象之间发生碰撞时,我运行以下代码:

Vector2 relativeVelocity = entity.Velocity - this.Velocity;
Vector2 normal = Vector2.Normalize (relativeVelocity);
float normalVelocity = Vector2.Dot (relativeVelocity, normal);
float restitution = Math.Min(this.Restitution, entity.Restitution);

float impulseScalar = -(1 + restitution) * normalVelocity;
impulseScalar /= this.InverseMass + entity.InverseMass;

Vector2 impulse = normal * impulseScalar;
this.Velocity -= this.InverseMass * impulse;
entity.Velocity += entity.InverseMass * impulse;    

当它靠近时,冲力不足以将两个碰撞的物体分开,导致被卡住的物体无法向任何方向移动。一定有点不对劲,但是什么?任何帮助都会很棒

所以,让冲动更大。记住浮点运算是不精确的。你能给我们举个例子吗?越简单越好。冲动不应该负责分离两个物体。您需要计算穿透向量,并通过使用该向量简单地更改对象的位置来分离对象。然后,应使用脉冲将两个对象设置在其新轨迹上。如果你有兴趣看到一个完全实现的解决方案,只要说,我会给出一个答案。