fix 3rd person not raycasting correctly when viewing player from front

This commit is contained in:
Moritz Zwerger 2023-11-01 19:08:38 +01:00
parent 4491522e6b
commit 50ca412424
No known key found for this signature in database
GPG Key ID: 5CAD791931B09AC4

View File

@ -57,12 +57,12 @@ class ThirdPersonView(
} }
private fun update(position: Vec3d, front: Vec3) { private fun update(position: Vec3d, front: Vec3) {
val target = camera.context.connection.camera.target.raycastBlock(position, -front.toVec3d).first val front = if (inverse) -front else front
val target = camera.context.connection.camera.target.raycastBlock(position, front.toVec3d).first
val distance = target?.distance?.let { minOf(it, MAX_DISTANCE) } ?: MAX_DISTANCE val distance = target?.distance?.let { minOf(it, MAX_DISTANCE) } ?: MAX_DISTANCE
val front = if (inverse) front else -front this.eyePosition = if (distance <= 0.0) position else position + (front * (distance - MIN_MARGIN))
this.eyePosition = if (distance <= 0.0) position else position + (-front * (distance - MIN_MARGIN)) this.front = -front
this.front = front
} }
override fun onAttach(previous: CameraView?) { override fun onAttach(previous: CameraView?) {