当我正在处理的项目中的两个对象之间发生冲突时,我运行以下代码:
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;
虽然它确实接近,但是冲动不足以将两个碰撞对象分开并导致被卡住的物体无法向任何方向移动。有些东西必须稍微关闭,但是什么?任何帮助都会很棒!