这是我用来防止这一糟糕事故发生在我心爱的角色身上的机制:
void onCollision(Set<Vector2> intersectionPoints, PositionComponent other) {
print(
"other is $other and intersectionPoints length is ${intersectionPoints.length}");
if (other is Brick && intersectionPoints.length == 2) {
isOnGround = true;
final intersectionsVector=
(intersectionPoints.elementAt(0) + intersectionPoints.elementAt(1)) /
2;
final collisionVector = absoluteCenter - intersectionsVector;
final penetrationDistance = size.x / 2 - collisionVector.length;
collisionVector.normalize();
if (Vector2(0, -1).dot(collisionVector) > 0.9) {
isOnGround = true;
}
position += collisionVector.scaled(penetrationDistance);
}
super.onCollision(intersectionPoints, other);
}
我的大部分游戏甚至变量的灵感都来自于火焰的Ember角色, 唯一的区别是Ember游戏不使用CameraComponent.Follow(播放器),但我使用. 一切都很顺利,我的角色走得很开心,突然他穿过了地面,死了.
所以我加了这个,看看什么是什么:
print(
"other is $other and intersectionPoints length is ${intersectionPoints.length}");
我看到的唯一问题是交叉点的长度是1的一些倍,也许这就是我的角色倒下的时间.我也不知道为什么. 我为我的播放器使用CircleHitBox,为我的砖块(平台)使用RecanglehitBox. 那么我怎么才能更好地处理这件事呢.谢谢