use meters in config
This commit is contained in:
@@ -32,16 +32,16 @@ void MovementIntentSystem::tick(EntityAdmin& admin)
|
||||
if (intent.priority == 0)
|
||||
{
|
||||
// No movement intent: brake using available thrust.
|
||||
const float linearBraking = std::min(body.velocity.length(),
|
||||
body.maneuveringAccelerationPerTick);
|
||||
body.linearAcceleration = (body.velocity.length() > 0.0001f)
|
||||
? -body.velocity.normalized() * linearBraking
|
||||
const float linearBraking = std::min(body.velocity_tpt.length(),
|
||||
body.maneuveringAcceleration_tptt);
|
||||
body.linearAcceleration_tptt = (body.velocity_tpt.length() > 0.0001f)
|
||||
? -body.velocity_tpt.normalized() * linearBraking
|
||||
: QVector2D(0.0f, 0.0f);
|
||||
|
||||
const float angBraking = std::min(std::abs(body.angularVelocity),
|
||||
body.angularAccelerationPerTick);
|
||||
body.angularAcceleration =
|
||||
(body.angularVelocity >= 0.0f) ? -angBraking : angBraking;
|
||||
const float angBraking = std::min(std::abs(body.angularVelocity_rpt),
|
||||
body.maxAngularAcceleration_rptt);
|
||||
body.angularAcceleration_rptt =
|
||||
(body.angularVelocity_rpt >= 0.0f) ? -angBraking : angBraking;
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -52,8 +52,8 @@ void MovementIntentSystem::tick(EntityAdmin& admin)
|
||||
{
|
||||
// Already at target: no new thrust. The ship drifts; it will
|
||||
// re-approach next tick once it has moved away.
|
||||
body.linearAcceleration = QVector2D(0.0f, 0.0f);
|
||||
body.angularAcceleration = 0.0f;
|
||||
body.linearAcceleration_tptt = QVector2D(0.0f, 0.0f);
|
||||
body.angularAcceleration_rptt = 0.0f;
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -62,11 +62,11 @@ void MovementIntentSystem::tick(EntityAdmin& admin)
|
||||
const float desiredAngle = std::atan2(delta.y(), delta.x());
|
||||
const float angleDiff = wrapAngle(desiredAngle - facing.radians);
|
||||
|
||||
const float rotDelta = std::max(-body.angularAccelerationPerTick,
|
||||
const float rotDelta = std::max(-body.maxAngularAcceleration_rptt,
|
||||
std::min(angleDiff,
|
||||
body.angularAccelerationPerTick));
|
||||
body.maxAngularAcceleration_rptt));
|
||||
|
||||
float newAngVel = body.angularVelocity + rotDelta;
|
||||
float newAngVel = body.angularVelocity_rpt + rotDelta;
|
||||
|
||||
// Overshoot prevention: if the accumulated angular velocity already
|
||||
// exceeds the remaining angle, snap it to exactly that angle so the
|
||||
@@ -77,8 +77,8 @@ void MovementIntentSystem::tick(EntityAdmin& admin)
|
||||
newAngVel = angleDiff;
|
||||
}
|
||||
|
||||
body.angularAcceleration = newAngVel - body.angularVelocity;
|
||||
// DynamicBodySystem applies the clamp to maxRotationSpeedPerTick after
|
||||
body.angularAcceleration_rptt = newAngVel - body.angularVelocity_rpt;
|
||||
// DynamicBodySystem applies the clamp to maxRotationSpeed_rpt after
|
||||
// integrating, so we do not clamp here.
|
||||
|
||||
// --- Linear acceleration ---
|
||||
@@ -90,22 +90,22 @@ void MovementIntentSystem::tick(EntityAdmin& admin)
|
||||
const QVector2D facingVec(std::cos(projectedRadians),
|
||||
std::sin(projectedRadians));
|
||||
|
||||
const float manAccel = body.maneuveringAccelerationPerTick;
|
||||
const float stoppingDist = (body.maxSpeedPerTick * body.maxSpeedPerTick)
|
||||
const float manAccel = body.maneuveringAcceleration_tptt;
|
||||
const float stoppingDist = (body.maxSpeed_tpt * body.maxSpeed_tpt)
|
||||
/ (2.0f * manAccel);
|
||||
// Cap to dist so the ship never overshoots the target in a single tick.
|
||||
const float baseDesiredSpeed = (dist <= stoppingDist)
|
||||
? std::sqrt(2.0f * manAccel * dist)
|
||||
: body.maxSpeedPerTick;
|
||||
: body.maxSpeed_tpt;
|
||||
const float desiredSpeed = std::min(dist, baseDesiredSpeed);
|
||||
|
||||
const QVector2D desiredVel = delta.normalized() * desiredSpeed;
|
||||
const QVector2D velError = desiredVel - body.velocity;
|
||||
const QVector2D velError = desiredVel - body.velocity_tpt;
|
||||
|
||||
const float mainAligned = std::max(0.0f,
|
||||
QVector2D::dotProduct(velError, facingVec));
|
||||
const float mainApplied = std::min(mainAligned,
|
||||
body.mainAccelerationPerTick);
|
||||
body.mainAcceleration_tptt);
|
||||
const QVector2D mainDelta = facingVec * mainApplied;
|
||||
|
||||
const QVector2D remaining = velError - mainDelta;
|
||||
@@ -114,7 +114,7 @@ void MovementIntentSystem::tick(EntityAdmin& admin)
|
||||
? remaining.normalized() * manAccel
|
||||
: remaining;
|
||||
|
||||
body.linearAcceleration = mainDelta + maneuverDelta;
|
||||
body.linearAcceleration_tptt = mainDelta + maneuverDelta;
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user