@adatechnology/game-vehicles-driving 0.2.30 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -287,6 +287,8 @@ interface SemiSimSpec {
287
287
  finalDrive: number;
288
288
  /** Share of the engine torque that reaches the ground. */
289
289
  efficiency: number;
290
+ /** What the physics engine's vehicle multiplies the engine torque by (the semi-simulation ignores it; 1 when omitted): see `PHYSICS_TORQUE_SCALE`. */
291
+ physicsTorqueScale?: number;
290
292
  /** Upshift above this fraction of the redline; downshift under `downshiftRpm` fraction. */
291
293
  upshiftFraction: number;
292
294
  downshiftFraction: number;
@@ -716,13 +716,14 @@ var GameVehiclesDriving = (() => {
716
716
 
717
717
  // src/semi/from-stats.ts
718
718
  var RIDER_MASS_KG = 75;
719
- var MOTORCYCLE_POWER_FACTOR = 1.3;
720
719
  var MOTORCYCLE_POWER_RATING_1 = 11800 / (132 + RIDER_MASS_KG);
721
720
  var MOTORCYCLE_POWER_RATING_10 = 33400 / (168 + RIDER_MASS_KG);
722
- var motorcyclePower = (rating) => MOTORCYCLE_POWER_FACTOR * (MOTORCYCLE_POWER_RATING_1 + (MOTORCYCLE_POWER_RATING_10 - MOTORCYCLE_POWER_RATING_1) * (rating - 1) / 9);
721
+ var motorcyclePower = (rating) => MOTORCYCLE_POWER_RATING_1 + (MOTORCYCLE_POWER_RATING_10 - MOTORCYCLE_POWER_RATING_1) * (rating - 1) / 9;
722
+ var PHYSICS_TORQUE_SCALE = { car: 1.45, motorcycle: 1.3 };
723
723
  var carPower = (rating) => (0.06 + 0.015 * rating) * (defaultSemiSpec.engine.peakRpm * 2 * Math.PI / 60);
724
+ var TRACKED_POWER = 20.05;
724
725
  var peakTorqueOf = (type, rating, mass, peakRpm) => {
725
- const power = type === "motorcycle" ? motorcyclePower(rating) : carPower(rating);
726
+ const power = type === "motorcycle" ? motorcyclePower(rating) : type === "tracked" ? TRACKED_POWER : carPower(rating);
726
727
  return mass * power * 60 / (2 * Math.PI * peakRpm);
727
728
  };
728
729
  var cyclistFor = (top, wheelRadius) => {
@@ -778,6 +779,7 @@ var GameVehiclesDriving = (() => {
778
779
  gears,
779
780
  drag,
780
781
  brakeForce,
782
+ ...type === "car" || type === "motorcycle" ? { physicsTorqueScale: PHYSICS_TORQUE_SCALE[type] } : {},
781
783
  tyre: { ...spec.tyre, friction: 0.8 + 0.03 * stats.handling },
782
784
  ...pedal ? { pedal } : {},
783
785
  ...tracks ? { tracks } : {}
@@ -1380,6 +1382,7 @@ var GameVehiclesDriving = (() => {
1380
1382
  var CLUTCH_STRENGTH = 10;
1381
1383
  var CLUTCH_SLIP = 0.03;
1382
1384
  var BICYCLE_WHEEL_INERTIA = 0.1;
1385
+ var BICYCLE_IDLE_CADENCE_RPM = 40;
1383
1386
  var WHEEL_INERTIA_PER_MASS = 8e-4;
1384
1387
  var REFERENCE_RADIUS = 0.32;
1385
1388
  var MIN_WHEEL_INERTIA = 0.02;
@@ -1392,6 +1395,12 @@ var GameVehiclesDriving = (() => {
1392
1395
  var MOTORCYCLE_TRANSMISSION = { switchTime: 0.05, clutchReleaseTime: 0.07, switchLatency: 0.05 };
1393
1396
  var clutchFor = (peakTorque, maxRpm) => Math.max(CLUTCH_STRENGTH, peakTorque / (CLUTCH_SLIP * (maxRpm * 2 * Math.PI / 60)));
1394
1397
  var clamp5 = (x, low, high) => Math.max(low, Math.min(high, x));
1398
+ var pedalCurve = (pedal) => {
1399
+ const redline = pedal.cadenceRpm * 1.5;
1400
+ const idle = BICYCLE_IDLE_CADENCE_RPM;
1401
+ const heldWatts = (cadence) => pedal.cadenceRpm / cadence;
1402
+ return [[0, heldWatts(idle)], [idle / redline, heldWatts(idle)], [pedal.cadenceRpm / redline, 1], [1, 0]];
1403
+ };
1395
1404
  var torqueCurve = (spec) => {
1396
1405
  const { idleRpm, peakRpm, redlineRpm, peakTorque } = spec.engine;
1397
1406
  const at = (rpm) => torqueAt(spec, rpm) / peakTorque;
@@ -1468,7 +1477,7 @@ var GameVehiclesDriving = (() => {
1468
1477
  gears: pedal.gears.map((ratio) => 1 / ratio),
1469
1478
  reverseGears: [],
1470
1479
  differentialRatio: 1,
1471
- torqueCurve: [[0, 1], [0.67, 1], [1, 0]],
1480
+ torqueCurve: pedalCurve(pedal),
1472
1481
  transmission: { shiftUpRpm: pedal.cadenceRpm * 0.95, shiftDownRpm: pedal.cadenceRpm * 0.5, clutchStrength: clutchFor(pedal.watts / crankSpeed, pedal.cadenceRpm * 1.5) }
1473
1482
  };
1474
1483
  }
@@ -1476,7 +1485,7 @@ var GameVehiclesDriving = (() => {
1476
1485
  return {
1477
1486
  engineDamping: ENGINE_DAMPING,
1478
1487
  engineInertia: ENGINE_INERTIA_PER_TORQUE * spec.engine.peakTorque,
1479
- maxTorque: spec.engine.peakTorque * spec.efficiency * (ENGINE_FLOOR + (1 - ENGINE_FLOOR) * health),
1488
+ maxTorque: spec.engine.peakTorque * (spec.physicsTorqueScale ?? 1) * spec.efficiency * (ENGINE_FLOOR + (1 - ENGINE_FLOOR) * health),
1480
1489
  minRpm: spec.engine.idleRpm,
1481
1490
  maxRpm: spec.engine.redlineRpm,
1482
1491
  gears: spec.gears,