【发布时间】:2015-06-15 17:31:48
【问题描述】:
当一个顶点与它发生碰撞时,我试图将一个同时具有速度和角速度的多边形从(不可移动的)墙上弹开。我可以检测到碰撞,并且我已经弄清楚了如何计算输入并知道我需要什么输出,但是无法找到或制定响应的实现。任何帮助将不胜感激。
function collisionResponse(
c, // object center of mass position
v, // velocity of object
a, // the angular velocity of the object
p, // point of contact with line
n // normalized normal of line
) {
// Make a vector from center mass to contact point
cp = p - c;
// Total velocity at contact point (add angular effect)
pv.x = v.x - cp.y * a;
pv.y = v.y + cp.x * a;
// Reflect point of contact velocity off the line (wall)
rv = reflect( pv, n );
// ..magic happens.. ??
result.v = ?? // resulting object velocity
result.a = ?? // resulting object angular velocity
return result;
}
【问题讨论】:
标签: math game-physics