physics: abort entity movement if collisions would increase distance

This commit is contained in:
Lukas 2021-05-01 14:13:54 +02:00
parent aa20dc3441
commit 7236ad0bc8

View File

@ -243,8 +243,9 @@ abstract class Entity(
testDelta.y = STEP_HEIGHT
val stepMovementY = collisionsToCheck.computeOffset(aabb + testDelta, -STEP_HEIGHT, Axes.Y)
if (stepMovementY < 0 && stepMovementY >= -STEP_HEIGHT) {
delta.y = STEP_HEIGHT + stepMovementY
aabb.offsetAssign(0f, delta.y, 0f)
testDelta.y = STEP_HEIGHT + stepMovementY
aabb.offsetAssign(0f, testDelta.y, 0f)
delta.y += testDelta.y
}
}
val xPriority = delta.x > delta.z
@ -268,6 +269,9 @@ abstract class Entity(
velocity.x = 0.0f
}
}
if (delta.length() > deltaPosition.length() + STEP_HEIGHT) {
return Vec3() // abort all movement if the collision system would move the entity further than wanted
}
return delta
}