Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Speed and mass dependent stabilization #371

Merged
merged 2 commits into from
Jul 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading