小编Rai*_*den的帖子

计算碰撞后的角速度

我已经将碰撞分辨率的线性分量相对较好地降低了,但是我无法弄清楚如何对角度分量做同样的事情.从我读过的,它就像...... torque= point of collisionx linear velocity.(交叉产品)我试图将我在代码中找到示例合并,但实际上当对象碰撞时我看不到任何旋转.另一个小提琴完美地适用于分离轴定理和角速度计算的基本实现.这就是我想出来的......

属性定义(方向,角速度和角加速度):

rotation: 0,
angularVelocity: 0,
angularAcceleration: 0
Run Code Online (Sandbox Code Playgroud)

计算碰撞响应中的角速度:

var pivotA = this.vector(bodyA.x, bodyA.y);
bodyA.angularVelocity = 1 * 0.2 * (bodyA.angularVelocity / Math.abs(bodyA.angularVelocity)) * pivotA.subtract(isCircle ? pivotA.add(bodyA.radius) : {
  x: pivotA.x + boundsA.width,
  y: pivotA.y + boundsA.height
}).vCross(bodyA.velocity);
var pivotB = this.vector(bodyB.x, bodyB.y);
bodyB.angularVelocity = 1 * 0.2 * (bodyB.angularVelocity / Math.abs(bodyB.angularVelocity)) * pivotB.subtract(isCircle ? pivotB.add(bodyB.radius) : {
  x: pivotB.x + boundsB.width,
  y: pivotB.y + …
Run Code Online (Sandbox Code Playgroud)

javascript html5 canvas game-physics

3
推荐指数
1
解决办法
1452
查看次数

标签 统计

canvas ×1

game-physics ×1

html5 ×1

javascript ×1