From 4474026fd4fd8c226f03ea68cd15ff111f434733 Mon Sep 17 00:00:00 2001 From: DBotThePony Date: Sun, 20 Feb 2022 21:31:09 +0700 Subject: [PATCH] Try to resolve ghost collision --- src/main/kotlin/ru/dbotthepony/kstarbound/Main.kt | 4 ++-- .../kstarbound/world/entities/AliveEntity.kt | 11 +++++++++++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/main/kotlin/ru/dbotthepony/kstarbound/Main.kt b/src/main/kotlin/ru/dbotthepony/kstarbound/Main.kt index 0ac6a09b..9a832f4a 100644 --- a/src/main/kotlin/ru/dbotthepony/kstarbound/Main.kt +++ b/src/main/kotlin/ru/dbotthepony/kstarbound/Main.kt @@ -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) diff --git a/src/main/kotlin/ru/dbotthepony/kstarbound/world/entities/AliveEntity.kt b/src/main/kotlin/ru/dbotthepony/kstarbound/world/entities/AliveEntity.kt index 979b6ce1..7ecbe2b7 100644 --- a/src/main/kotlin/ru/dbotthepony/kstarbound/world/entities/AliveEntity.kt +++ b/src/main/kotlin/ru/dbotthepony/kstarbound/world/entities/AliveEntity.kt @@ -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(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(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 + } } } }