From 6a57a8580e9b1b3649c49778c0fbbf2e5bc9002d Mon Sep 17 00:00:00 2001 From: a dinosaur Date: Thu, 22 Aug 2024 03:52:21 +1000 Subject: [PATCH] reorder collision response so zipping up is prioritised over left if player gets stuck in a block --- Sources/Voxelotl/Player.swift | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/Sources/Voxelotl/Player.swift b/Sources/Voxelotl/Player.swift index a8cdf26..9c39015 100644 --- a/Sources/Voxelotl/Player.swift +++ b/Sources/Voxelotl/Player.swift @@ -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 {