mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-06-12 11:34:05 +09:00
more accurate floating point comparison with epsilon
This commit is contained in:
@@ -751,7 +751,7 @@ open class ActorHumanoid : ActorWithBody, Controllable, Pocketed, Factionable, L
|
||||
if (this is HasAssembledSprite) {
|
||||
try {
|
||||
val baseDelay = animDesc!!.getAnimByFrameName("ANIM_RUN").delay
|
||||
val moveSpeedMult = (controllerV?.x ?: 0.0).abs().coerceAtLeast(PHYS_EPSILON_VELO).toFloat() / 1.414f // FIXME empirical value
|
||||
val moveSpeedMult = (controllerV?.x ?: 0.0).abs().coerceAtLeast(0.001).toFloat() / 1.414f // FIXME empirical value
|
||||
val stride = scale.toFloat()
|
||||
val maxMoveSpeed = scale.sqrt().toFloat() // ActorWithBody uses scale.sqrt() for determining walk acceleration
|
||||
val scaleCompensation = stride / maxMoveSpeed
|
||||
|
||||
@@ -12,9 +12,7 @@ import net.torvald.terrarum.gameactors.*
|
||||
import net.torvald.terrarum.gameitems.mouseInInteractableRange
|
||||
import net.torvald.terrarum.langpack.Lang
|
||||
import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack
|
||||
import org.dyn4j.geometry.Vector2
|
||||
import java.util.*
|
||||
import kotlin.math.absoluteValue
|
||||
|
||||
/**
|
||||
* @param width of hitbox, in tiles, when the door is opened. Default to 2. Closed door always have width of 1. (this limits how big and thick the door can be)
|
||||
@@ -261,13 +259,16 @@ open class FixtureSwingingDoorBase : FixtureBase {
|
||||
}
|
||||
|
||||
private fun ActorWithBody.movingTowardsRight(): Boolean {
|
||||
return ((this.controllerV ?: Vector2()) + this.externalV).x >= PHYS_EPSILON_VELO
|
||||
// return ((this.controllerV ?: Vector2()) + this.externalV).x >= PHYS_EPSILON_VELO
|
||||
return (((this.controllerV?.x ?: 0.0) / this.externalV.x).let { if (it.isNaN()) 0.0 else it } - 1) >= PHYS_EPSILON_DIST
|
||||
}
|
||||
private fun ActorWithBody.movingTowardsLeft(): Boolean {
|
||||
return ((this.controllerV ?: Vector2()) + this.externalV).x <= -PHYS_EPSILON_VELO
|
||||
// return ((this.controllerV ?: Vector2()) + this.externalV).x <= -PHYS_EPSILON_VELO
|
||||
return (((this.controllerV?.x ?: 0.0) / this.externalV.x).let { if (it.isNaN()) 0.0 else it } - 1) <= PHYS_EPSILON_DIST
|
||||
}
|
||||
private fun ActorWithBody.notMoving(): Boolean {
|
||||
return ((this.controllerV ?: Vector2()) + this.externalV).x.absoluteValue < PHYS_EPSILON_VELO
|
||||
// return ((this.controllerV ?: Vector2()) + this.externalV).x.absoluteValue < PHYS_EPSILON_VELO
|
||||
return ActorWithBody.isCloseEnough(this.controllerV?.x ?: 0.0, this.externalV.x)
|
||||
}
|
||||
|
||||
private var doorCloseQueueTimer = 0f
|
||||
|
||||
Reference in New Issue
Block a user