diff --git a/src/net/torvald/terrarum/gameactors/ActorWithBody.kt b/src/net/torvald/terrarum/gameactors/ActorWithBody.kt index 1553a97dc..e2a255c9c 100644 --- a/src/net/torvald/terrarum/gameactors/ActorWithBody.kt +++ b/src/net/torvald/terrarum/gameactors/ActorWithBody.kt @@ -891,15 +891,15 @@ open class ActorWithBody : Actor { // points to the EDGE of the tile in world dimension (don't use this directly to get tilewise coord!!) val offendingTileWorldX = if (selfCollisionStatus in listOf(6, 12)) - newHitbox.endX.div(TILE_SIZE).floorToDouble() * TILE_SIZE - PHYS_EPSILON_DIST + newHitbox.endX.div(TILE_SIZE).floorToDouble() * TILE_SIZE - PHYS_EPSILON_DIST // adding/subbing fixes a bug where player stops midair when L/R is held and moving down from the platform else - newHitbox.startX.div(TILE_SIZE).ceilToDouble() * TILE_SIZE + newHitbox.startX.div(TILE_SIZE).ceilToDouble() * TILE_SIZE + PHYS_EPSILON_DIST // adding/subbing fixes a bug where player stops midair when L/R is held and moving down from the platform // points to the EDGE of the tile in world dimension (don't use this directly to get tilewise coord!!) val offendingTileWorldY = if (selfCollisionStatus in listOf(3, 6)) - newHitbox.endY.div(TILE_SIZE).floorToDouble() * TILE_SIZE - PHYS_EPSILON_DIST + newHitbox.endY.div(TILE_SIZE).floorToDouble() * TILE_SIZE - PHYS_EPSILON_DIST // adding/subbing fixes a bug where player stops midair when L/R is held and moving down from the platform else - newHitbox.startY.div(TILE_SIZE).ceilToDouble() * TILE_SIZE + newHitbox.startY.div(TILE_SIZE).ceilToDouble() * TILE_SIZE + PHYS_EPSILON_DIST // adding/subbing fixes a bug where player stops midair when L/R is held and moving down from the platform val offendingHitboxPointX = if (selfCollisionStatus in listOf(6, 12)) newHitbox.endX diff --git a/src/net/torvald/terrarum/gameactors/Hitbox.kt b/src/net/torvald/terrarum/gameactors/Hitbox.kt index 9a9583bef..f5d67bdb5 100644 --- a/src/net/torvald/terrarum/gameactors/Hitbox.kt +++ b/src/net/torvald/terrarum/gameactors/Hitbox.kt @@ -1,5 +1,6 @@ package net.torvald.terrarum.gameactors +import com.jme3.math.FastMath import net.torvald.terrarum.Point2d import net.torvald.terrarum.printStackTrace import org.dyn4j.geometry.Vector2 @@ -190,6 +191,15 @@ class Hitbox { companion object { fun fromTwoPoints(x1: Double, y1: Double, x2: Double, y2: Double, nowarn: Boolean = false) = Hitbox(x1, y1, x2 - x1, y2 - y1, nowarn) + + fun lerp(fraction: Double, a: Hitbox, b: Hitbox): Hitbox { + return Hitbox( + FastMath.interpolateLinear(fraction, a.startX, b.startX), + FastMath.interpolateLinear(fraction, a.startY, b.startY), + FastMath.interpolateLinear(fraction, a.width, b.width), + FastMath.interpolateLinear(fraction, a.height, b.height) + ) + } } operator fun minus(other: Hitbox): Vector2 {