新增arcadeRigidbody组件, 可以用于简单的,街机风格的物理学

This commit is contained in:
yhh
2020-12-07 11:48:42 +08:00
parent 2a0d4ef4dd
commit bddae046a0
12 changed files with 835 additions and 82 deletions

View File

@@ -182,7 +182,7 @@ module es {
* @param motion
* @param result
*/
public collidesWith(collider: Collider, motion: Vector2, result: CollisionResult): boolean {
public collidesWith(collider: Collider, motion: Vector2, result: CollisionResult = new CollisionResult()): boolean {
// 改变形状的位置,使它在移动后的位置,这样我们可以检查重叠
let oldPosition = this.entity.position.clone();
this.entity.position = Vector2.add(this.entity.position, motion);
@@ -196,5 +196,19 @@ module es {
return didCollide;
}
/**
* 检查这个对撞机是否与对撞机发生碰撞。如果碰撞则返回true结果将被填充
* @param collider
* @param result
*/
public collidesWithNonMotion(collider: Collider, result: CollisionResult = new CollisionResult()): boolean {
if (this.shape.collidesWithShape(collider.shape, result)) {
result.collider = collider;
return true;
}
return false;
}
}
}