mirror of
https://github.com/GayPizzaSpecifications/voxelotl-engine.git
synced 2025-08-02 13:00:53 +00:00
restore player collision
This commit is contained in:
parent
9dd56faa4e
commit
bcc56956b3
@ -68,11 +68,37 @@ struct Player {
|
|||||||
self._velocity.y -= Self.gravityCoeff * deltaTime
|
self._velocity.y -= Self.gravityCoeff * deltaTime
|
||||||
|
|
||||||
// Move & handle collision
|
// Move & handle collision
|
||||||
|
let checkCorner = { (bounds: AABB, corner: SIMD3<Float>) -> Optional<AABB> in
|
||||||
|
let blockPos = SIMD3(floor(corner.x), floor(corner.y), floor(corner.z))
|
||||||
|
if case BlockType.solid = chunk.getBlock(at: SIMD3<Int>(blockPos)).type {
|
||||||
|
let blockGeometry = AABB(from: blockPos, to: blockPos + 1)
|
||||||
|
if bounds.touching(blockGeometry) {
|
||||||
|
return blockGeometry
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
let checkCollision = { (position: SIMD3<Float>) -> Optional<AABB> in
|
let checkCollision = { (position: SIMD3<Float>) -> Optional<AABB> in
|
||||||
let bounds = Self.bounds + position
|
let bounds = Self.bounds + position
|
||||||
//if bounds.touching(blockGeometry) {
|
let corners: [SIMD3<Float>] = [
|
||||||
// return box.geometry
|
.init(bounds.left, bounds.bottom, bounds.far),
|
||||||
//}
|
.init(bounds.right, bounds.bottom, bounds.far),
|
||||||
|
.init(bounds.left, bounds.bottom, bounds.near),
|
||||||
|
.init(bounds.right, bounds.bottom, bounds.near),
|
||||||
|
.init(bounds.left, bounds.center.y, bounds.far),
|
||||||
|
.init(bounds.right, bounds.center.y, bounds.far),
|
||||||
|
.init(bounds.left, bounds.center.y, bounds.near),
|
||||||
|
.init(bounds.right, bounds.center.y, bounds.near),
|
||||||
|
.init(bounds.left, bounds.top, bounds.far),
|
||||||
|
.init(bounds.right, bounds.top, bounds.far),
|
||||||
|
.init(bounds.left, bounds.top, bounds.near),
|
||||||
|
.init(bounds.right, bounds.top, bounds.near)
|
||||||
|
]
|
||||||
|
for corner in corners {
|
||||||
|
if let geometry = checkCorner(bounds, corner) {
|
||||||
|
return geometry
|
||||||
|
}
|
||||||
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
self._position.x += self._velocity.x * deltaTime
|
self._position.x += self._velocity.x * deltaTime
|
||||||
|
Loading…
Reference in New Issue
Block a user