reorder collision response so zipping up is prioritised over left if player gets stuck in a block

This commit is contained in:
a dinosaur 2024-08-22 03:52:21 +10:00
parent 7eb880f0b7
commit 6a57a8580e

View File

@ -113,6 +113,19 @@ struct Player {
}
return nil
}
self._position.y += self._velocity.y * deltaTime
if let aabb = checkCollision(self._velocity.y > 0 ? self._position + .down * Self.epsilon : self.position) {
if self._velocity.y < 0 {
self._position.y = aabb.top + Self.epsilon
self._onGround = true
} else {
self._position.y = aabb.bottom - Self.height - Self.epsilon
self._onGround = false
}
self._velocity.y = 0
} else {
self._onGround = false
}
self._position.x += self._velocity.x * deltaTime
if let aabb = checkCollision(self._position) {
if self._velocity.x < 0 {
@ -131,19 +144,6 @@ struct Player {
}
self._velocity.z = 0
}
self._position.y += self._velocity.y * deltaTime
if let aabb = checkCollision(self._velocity.y > 0 ? self._position + .down * Self.epsilon : self.position) {
if self._velocity.y < 0 {
self._position.y = aabb.top + Self.epsilon
self._onGround = true
} else {
self._position.y = aabb.bottom - Self.height - Self.epsilon
self._onGround = false
}
self._velocity.y = 0
} else {
self._onGround = false
}
// Ground friction
if self._onGround {