File tree Expand file tree Collapse file tree 1 file changed +3
-3
lines changed Expand file tree Collapse file tree 1 file changed +3
-3
lines changed Original file line number Diff line number Diff line change @@ -42,7 +42,7 @@ if( entity.getComponent(Collider).collidesWithAny( deltaMovement, collisionResul
42
42
}
43
43
44
44
// 将实体移到新位置。 已经调整了deltaMovement为我们解决冲突。
45
- entity .position = Vector2 . add ( entity .position , deltaMovement );
45
+ entity .position = entity .position . add ( deltaMovement );
46
46
```
47
47
48
48
如果您需要对碰撞发生时的情况进行更多控制,则也可以手动检查是否与其他collider发生碰撞。 请注意,执行此操作时,deltaMovement不会为您调整。 解决冲突时,您需要考虑最小平移矢量。
@@ -54,7 +54,7 @@ let collisionResult = null;
54
54
if ( entity .getComponent (Collider ).collidesWith ( someOtherCollider , deltaMovement , collisionResult ) )
55
55
{
56
56
// 将实体移动到与命中Collider相邻的位置,然后记录CollisionResult
57
- entity .position = Vector2 . add ( entity .position , Vector2 . substract (deltaMovement , collisionResult .minimumTranslationVector ));
57
+ entity .position = entity .position . add (deltaMovement . sub ( collisionResult .minimumTranslationVector ));
58
58
console .log ( ` collision result: ${collisionResult } ` );
59
59
}
60
60
```
@@ -70,4 +70,4 @@ for( let collider of neighborColliders )
70
70
if ( entity .getComponent (Collider ).overlaps ( collider ) )
71
71
console .log ( ` 我们正在重叠一个collider : ${collider } ` );
72
72
}
73
- ```
73
+ ```
You can’t perform that action at this time.
0 commit comments