Try to resolve ghost collision

This commit is contained in:
DBotThePony 2022-02-20 21:31:09 +07:00
parent d9c4b0aee2
commit 4474026fd4
Signed by: DBot
GPG Key ID: DCC23B5715498507
2 changed files with 13 additions and 2 deletions

View File

@ -188,8 +188,8 @@ fun main() {
Starbound.pollCallbacks()
//ent.think(client.frameRenderTime)
//client.camera.pos.x = ent.position.x.toFloat()
//client.camera.pos.y = ent.position.y.toFloat()
client.camera.pos.x = ent.position.x.toFloat()
client.camera.pos.y = ent.position.y.toFloat()
//println(client.camera.velocity.toDoubleVector() * client.frameRenderTime * 0.1)

View File

@ -5,6 +5,7 @@ import ru.dbotthepony.kstarbound.world.World
import ru.dbotthepony.kvector.util2d.AABB
import ru.dbotthepony.kvector.vector.Color
import ru.dbotthepony.kvector.vector.ndouble.Vector2d
import ru.dbotthepony.kvector.vector.ndouble.times
import kotlin.math.absoluteValue
enum class Move {
@ -144,6 +145,11 @@ abstract class WalkableMovementController<T : IWalkableEntity>(entity: T) : Move
if (body.linearVelocity.x > -topSpeed) {
body.linearVelocity += Vector2d(x = -moveSpeed * delta)
// Ghost collision prevention
if (body.linearVelocity.x.absoluteValue < 1) {
body.linearVelocity += -delta * world.gravity * 2.0
}
}
}
@ -154,6 +160,11 @@ abstract class WalkableMovementController<T : IWalkableEntity>(entity: T) : Move
if (body.linearVelocity.x < topSpeed) {
body.linearVelocity += Vector2d(x = moveSpeed * delta)
// Ghost collision prevention
if (body.linearVelocity.x.absoluteValue < 1) {
body.linearVelocity += -delta * world.gravity * 2.0
}
}
}
}