Skip to content

Commit

Permalink
Update physics.md
Browse files Browse the repository at this point in the history
  • Loading branch information
esengine committed Aug 2, 2021
1 parent 95b8dc7 commit f9a99f8
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions docs/physics.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ if( entity.getComponent(Collider).collidesWithAny( deltaMovement, collisionResul
}

// 将实体移到新位置。 已经调整了deltaMovement为我们解决冲突。
entity.position = Vector2.add(entity.position, deltaMovement);
entity.position = entity.position.add(deltaMovement);
```

如果您需要对碰撞发生时的情况进行更多控制,则也可以手动检查是否与其他collider发生碰撞。 请注意,执行此操作时,deltaMovement不会为您调整。 解决冲突时,您需要考虑最小平移矢量。
Expand All @@ -54,7 +54,7 @@ let collisionResult = null;
if( entity.getComponent(Collider).collidesWith( someOtherCollider, deltaMovement, collisionResult ) )
{
// 将实体移动到与命中Collider相邻的位置,然后记录CollisionResult
entity.position = Vector2.add(entity.position, Vector2.substract(deltaMovement, collisionResult.minimumTranslationVector));
entity.position = entity.position.add(deltaMovement.sub(collisionResult.minimumTranslationVector));
console.log( `collision result: ${collisionResult}` );
}
```
Expand All @@ -70,4 +70,4 @@ for( let collider of neighborColliders )
if( entity.getComponent(Collider).overlaps( collider ) )
console.log( `我们正在重叠一个collider : ${collider}` );
}
```
```

0 comments on commit f9a99f8

Please sign in to comment.