From 612871eb2abbea2cfc1dbb1a811610ab08ea1c55 Mon Sep 17 00:00:00 2001 From: minjaesong Date: Mon, 9 Feb 2026 09:46:35 +0900 Subject: [PATCH] fix: moving platform is dragging player into the terrain again --- src/net/torvald/terrarum/gameactors/PhysContraption.kt | 8 +++++--- .../modulebasegame/gameactors/ActorTestPlatform.kt | 2 +- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/net/torvald/terrarum/gameactors/PhysContraption.kt b/src/net/torvald/terrarum/gameactors/PhysContraption.kt index d3bc53705..b90d4de0c 100644 --- a/src/net/torvald/terrarum/gameactors/PhysContraption.kt +++ b/src/net/torvald/terrarum/gameactors/PhysContraption.kt @@ -56,7 +56,7 @@ abstract class PhysContraption() : ActorWithBody() { val oldY = hitbox.startY // Set externalV to our contraption velocity so super translates the hitbox - externalV.set(contraptionVelocity.x, contraptionVelocity.y) + externalV.set(contraptionVelocity) // super.updateImpl handles: // - sprite updates @@ -72,6 +72,7 @@ abstract class PhysContraption() : ActorWithBody() { // --- Step 1: Move existing riders BEFORE mount detection --- // This keeps riders aligned with the contraption's new position so the // mount check doesn't fail when the contraption is moving fast. + val terrainDismounted = HashSet() for (riderId in actorsRiding.toList()) { val rider = INGAME.getActorByID(riderId) as? ActorWithBody ?: continue @@ -97,6 +98,7 @@ abstract class PhysContraption() : ActorWithBody() { rider.hitbox.setPositionY(oldRiderY) actorsRiding.remove(rider.referenceID) rider.platformsRiding.remove(this.referenceID) + terrainDismounted.add(rider.referenceID) continue } } @@ -156,6 +158,7 @@ abstract class PhysContraption() : ActorWithBody() { for (actor in candidates) { if (actorsRiding.contains(actor.referenceID)) continue + if (terrainDismounted.contains(actor.referenceID)) continue if (actor is ActorHumanoid && actor.downButtonHeld > 0) continue if (!isActorOnTop(actor)) continue @@ -215,7 +218,6 @@ abstract class PhysContraption() : ActorWithBody() { actor.platformsRiding.remove(this.referenceID) // Conservation of momentum: add contraption velocity as impulse - actor.externalV.x += contraptionVelocity.x - actor.externalV.y += contraptionVelocity.y + actor.externalV += contraptionVelocity } } diff --git a/src/net/torvald/terrarum/modulebasegame/gameactors/ActorTestPlatform.kt b/src/net/torvald/terrarum/modulebasegame/gameactors/ActorTestPlatform.kt index ebf8a3548..95f98a935 100644 --- a/src/net/torvald/terrarum/modulebasegame/gameactors/ActorTestPlatform.kt +++ b/src/net/torvald/terrarum/modulebasegame/gameactors/ActorTestPlatform.kt @@ -18,7 +18,7 @@ import kotlin.math.sin class ActorTestPlatform : ActorMovingPlatform(8) { /** Movement pattern index (0-3). */ - private val pattern: Int = (0..1).random() + private val pattern: Int = (0..3).random() /** Speed in pixels per tick (2.0 to 4.0). */ private val speed: Double = 2.0 + Math.random() * 2.0