Skip to content

Commit 87b2fac

Browse files
Merge pull request #371 from ValkyrienSkies/speed-dependent-stable
Speed and mass dependent stabilization
2 parents 99b6129 + 66b2cab commit 87b2fac

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

common/src/main/kotlin/org/valkyrienskies/eureka/EurekaConfig.kt

+8
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,14 @@ object EurekaConfig {
120120
@JsonSchema(description = "How fast a ship will stop. 1 = fast stop, 0 = slow stop")
121121
var linearStabilizeMaxAntiVelocity = 1.0
122122

123+
// Instability scaled with mass and squared speed
124+
@JsonSchema(description = "Stronger stabilization with higher mass, less at higher speeds.")
125+
var scaledInstability = 1000.0
126+
127+
// Unscaled linear instability cased by speed
128+
@JsonSchema(description = "Less stabilization at higher speed.")
129+
var unscaledInstability = 0.271828
130+
123131
@JsonSchema(description = "How fast a ship will stop and accelerate.")
124132
var linearMassScaling = 0.0002
125133

common/src/main/kotlin/org/valkyrienskies/eureka/ship/Stabilize.kt

+4-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import org.valkyrienskies.core.api.ships.PhysShip
66
import org.valkyrienskies.core.impl.game.ships.PhysShipImpl
77
import org.valkyrienskies.eureka.EurekaConfig
88
import kotlin.math.atan
9+
import kotlin.math.max
910

1011
fun stabilize(
1112
ship: PhysShipImpl,
@@ -46,7 +47,9 @@ fun stabilize(
4647
)
4748
)
4849

49-
stabilizationTorque.mul(EurekaConfig.SERVER.stabilizationTorqueConstant)
50+
val speed = ship.poseVel.vel.length()
51+
52+
stabilizationTorque.mul(EurekaConfig.SERVER.stabilizationTorqueConstant / max(1.0, speed * speed * EurekaConfig.SERVER.scaledInstability / ship.inertia.shipMass + speed * EurekaConfig.SERVER.unscaledInstability))
5053
forces.applyInvariantTorque(stabilizationTorque)
5154

5255
if (linear) {

0 commit comments

Comments
 (0)