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 testDelta.y = STEP_HEIGHT
val stepMovementY = collisionsToCheck.computeOffset(aabb + testDelta, -STEP_HEIGHT, Axes.Y) val stepMovementY = collisionsToCheck.computeOffset(aabb + testDelta, -STEP_HEIGHT, Axes.Y)
if (stepMovementY < 0 && stepMovementY >= -STEP_HEIGHT) { if (stepMovementY < 0 && stepMovementY >= -STEP_HEIGHT) {
delta.y = STEP_HEIGHT + stepMovementY testDelta.y = STEP_HEIGHT + stepMovementY
aabb.offsetAssign(0f, delta.y, 0f) aabb.offsetAssign(0f, testDelta.y, 0f)
delta.y += testDelta.y
} }
} }
val xPriority = delta.x > delta.z val xPriority = delta.x > delta.z
@ -268,6 +269,9 @@ abstract class Entity(
velocity.x = 0.0f 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 return delta
} }