Skip to content

Commit

Permalink
Merge pull request #371 from ValkyrienSkies/speed-dependent-stable
Browse files Browse the repository at this point in the history
Speed and mass dependent stabilization
  • Loading branch information
millennIumAMbiguity authored Jul 2, 2024
2 parents 99b6129 + 66b2cab commit 87b2fac
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,14 @@ object EurekaConfig {
@JsonSchema(description = "How fast a ship will stop. 1 = fast stop, 0 = slow stop")
var linearStabilizeMaxAntiVelocity = 1.0

// Instability scaled with mass and squared speed
@JsonSchema(description = "Stronger stabilization with higher mass, less at higher speeds.")
var scaledInstability = 1000.0

// Unscaled linear instability cased by speed
@JsonSchema(description = "Less stabilization at higher speed.")
var unscaledInstability = 0.271828

@JsonSchema(description = "How fast a ship will stop and accelerate.")
var linearMassScaling = 0.0002

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import org.valkyrienskies.core.api.ships.PhysShip
import org.valkyrienskies.core.impl.game.ships.PhysShipImpl
import org.valkyrienskies.eureka.EurekaConfig
import kotlin.math.atan
import kotlin.math.max

fun stabilize(
ship: PhysShipImpl,
Expand Down Expand Up @@ -46,7 +47,9 @@ fun stabilize(
)
)

stabilizationTorque.mul(EurekaConfig.SERVER.stabilizationTorqueConstant)
val speed = ship.poseVel.vel.length()

stabilizationTorque.mul(EurekaConfig.SERVER.stabilizationTorqueConstant / max(1.0, speed * speed * EurekaConfig.SERVER.scaledInstability / ship.inertia.shipMass + speed * EurekaConfig.SERVER.unscaledInstability))
forces.applyInvariantTorque(stabilizationTorque)

if (linear) {
Expand Down

0 comments on commit 87b2fac

Please sign in to comment.