mirror of
https://gitlab.bixilon.de/bixilon/minosoft.git
synced 2025-09-12 17:07:55 -04:00
physics: improve collisions (remove small margin from aabb)
This commit is contained in:
parent
08099c981d
commit
26e451c454
@ -73,10 +73,10 @@ abstract class Entity(
|
||||
|
||||
override var onGround = false
|
||||
|
||||
val defaultAABB: AABB
|
||||
private val defaultAABB: AABB
|
||||
get() {
|
||||
val halfWidth = dimensions.x / 2
|
||||
return AABB(Vec3(-halfWidth, 0.0f, -halfWidth), Vec3(halfWidth, dimensions.y, halfWidth)) grow HITBOX_MARGIN
|
||||
return AABB(Vec3(-halfWidth, 0.0f, -halfWidth), Vec3(halfWidth, dimensions.y, halfWidth))
|
||||
}
|
||||
|
||||
open val dimensions = Vec2(entityType.width, entityType.height)
|
||||
@ -103,9 +103,6 @@ abstract class Entity(
|
||||
|
||||
fun forceMove(deltaPosition: Vec3d) {
|
||||
previousPosition = Vec3d(position)
|
||||
if (onGround) {
|
||||
deltaPosition.y -= 0.00001f
|
||||
}
|
||||
position = position + deltaPosition
|
||||
}
|
||||
|
||||
@ -323,8 +320,6 @@ abstract class Entity(
|
||||
open fun setObjectData(data: Int) {}
|
||||
|
||||
companion object {
|
||||
private const val HITBOX_MARGIN = 1e-5f
|
||||
|
||||
private val BELOW_POSITION_MINUS = Vec3(0, 0.20000000298023224f, 0)
|
||||
}
|
||||
}
|
||||
|
@ -33,8 +33,7 @@ open class ItemFrame(connection: PlayConnection, entityType: EntityType, positio
|
||||
val itemRotation: Int
|
||||
get() = entityMetaData.sets.getInt(EntityMetaDataFields.ITEM_FRAME_ROTATION)
|
||||
|
||||
|
||||
@get:EntityMetaDataFunction(name = "Owner")
|
||||
@get:EntityMetaDataFunction(name = "Facing")
|
||||
var facing: Directions = Directions.NORTH
|
||||
|
||||
override fun setObjectData(data: Int) {
|
||||
|
@ -31,7 +31,7 @@ class CollisionDetector(val connection: PlayConnection) {
|
||||
|
||||
private fun getCollisionsToCheck(deltaPosition: Vec3d, aabb: AABB, ignoreUnloadedChunks: Boolean = true): VoxelShape {
|
||||
// also look at blocks further down to also cover blocks with a higher than normal hitbox (for example fences)
|
||||
val blockPositions = (aabb extend deltaPosition extend Directions.DOWN).blockPositions
|
||||
val blockPositions = (aabb extend deltaPosition extend Directions.DOWN grow COLLISION_BOX_MARGIN).blockPositions
|
||||
val result = VoxelShape()
|
||||
for (blockPosition in blockPositions) {
|
||||
val chunk = connection.world[blockPosition.chunkPosition]
|
||||
@ -168,4 +168,8 @@ class CollisionDetector(val connection: PlayConnection) {
|
||||
|
||||
return adjusted
|
||||
}
|
||||
|
||||
companion object {
|
||||
private const val COLLISION_BOX_MARGIN = 0.001
|
||||
}
|
||||
}
|
||||
|
@ -109,7 +109,7 @@ class AABB(
|
||||
return this extend direction.vector
|
||||
}
|
||||
|
||||
infix fun grow(value: Float): AABB {
|
||||
infix fun grow(value: Double): AABB {
|
||||
return AABB(min - value, max + value)
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user