@adatechnology/game-vehicles-driving 0.2.9 → 0.2.10
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 +25 -8
- package/dist/index.global.js +45 -3
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +45 -3
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
|
@@ -252,6 +252,8 @@ interface SemiSimSpec {
|
|
|
252
252
|
maxSteer: number;
|
|
253
253
|
/** Total brake force, newtons, split by the wheel loads. */
|
|
254
254
|
brakeForce: number;
|
|
255
|
+
/** Anti-lock brakes (default true). Without them a hard stop locks the wheels: they slide on less grip and the car does not steer. */
|
|
256
|
+
abs?: boolean;
|
|
255
257
|
engine: {
|
|
256
258
|
idleRpm: number;
|
|
257
259
|
peakRpm: number;
|
|
@@ -288,6 +290,8 @@ interface VehicleCondition {
|
|
|
288
290
|
tyres?: readonly number[];
|
|
289
291
|
engine?: number;
|
|
290
292
|
suspension?: number;
|
|
293
|
+
/** How much of the brake force is left, 0..1: worn or broken brakes, no brake fluid. */
|
|
294
|
+
brakes?: number;
|
|
291
295
|
}
|
|
292
296
|
interface SemiInput extends DriveInput {
|
|
293
297
|
/** Forces a gear (1-based, 0 = neutral, -1 = reverse). Absent = automatic. */
|
|
@@ -303,6 +307,8 @@ interface SemiWorld {
|
|
|
303
307
|
ground?(x: number, z: number): SemiGround;
|
|
304
308
|
}
|
|
305
309
|
interface SemiState {
|
|
310
|
+
/** Temperature of the brakes, °C: hard stops heat them, and past about 350 °C they fade. */
|
|
311
|
+
brakeHeat?: number;
|
|
306
312
|
x: number;
|
|
307
313
|
z: number;
|
|
308
314
|
yaw: number;
|
|
@@ -365,12 +371,6 @@ interface SemiDriver extends Omit<Driver, 'step' | 'state'> {
|
|
|
365
371
|
events: SemiEvent[];
|
|
366
372
|
};
|
|
367
373
|
}
|
|
368
|
-
/**
|
|
369
|
-
* The semi-simulation driver (Frota document, section 03): a single rigid body with a low centre of mass, a spring and damper on each wheel
|
|
370
|
-
* measured against the ground under it, separate longitudinal and lateral tyre forces inside a friction circle, an automatic gearbox with a
|
|
371
|
-
* simulated RPM, a handbrake that locks the rear wheels, surfaces with their grip, and damage that changes how it drives. No team code exists
|
|
372
|
-
* for it: the numbers are the document's and the tests check them.
|
|
373
|
-
*/
|
|
374
374
|
declare function createSemiSimDriver(specification?: Partial<SemiSimSpec>, options?: SemiSimOptions): SemiDriver;
|
|
375
375
|
|
|
376
376
|
/** Kinetic energy of a vehicle against a body: `0.5 * mass * speed²` (joules, with kg and m/s). Frota document, section 08. */
|
|
@@ -398,8 +398,25 @@ interface BodyDimensions {
|
|
|
398
398
|
}
|
|
399
399
|
/**
|
|
400
400
|
* A semi-simulation spec for a two-axle vehicle from its design ratings: the grip follows the handling, the torque follows the acceleration,
|
|
401
|
-
*
|
|
401
|
+
* the air drag is set so that the top gear tops out at the design top speed, and the brake force follows the mass.
|
|
402
402
|
*/
|
|
403
403
|
declare function semiSpecFromStats(stats: DesignStats, body: BodyDimensions, base?: Partial<SemiSimSpec>): SemiSimSpec;
|
|
404
404
|
|
|
405
|
-
|
|
405
|
+
/** Matches a damage model's wheels to a driver's: each wheel of the spec takes the health of the tyre nearest to it. */
|
|
406
|
+
|
|
407
|
+
type DamagedTyre = {
|
|
408
|
+
/** Where the tyre is in the vehicle's space, metres: x forward, z to the side. */
|
|
409
|
+
readonly x: number;
|
|
410
|
+
readonly z: number;
|
|
411
|
+
/** 0 flat or gone, 1 whole. */
|
|
412
|
+
readonly health: number;
|
|
413
|
+
};
|
|
414
|
+
type DamageReport = {
|
|
415
|
+
readonly tyres: readonly DamagedTyre[];
|
|
416
|
+
readonly brakes?: number;
|
|
417
|
+
readonly engine?: number;
|
|
418
|
+
readonly suspension?: number;
|
|
419
|
+
};
|
|
420
|
+
declare function conditionFromDamage(spec: Pick<SemiSimSpec, 'wheels'>, report: DamageReport): VehicleCondition;
|
|
421
|
+
|
|
422
|
+
export { type ArcadeOptions, type ArcadeSpec, type BodyDimensions, type CrashRules, type DamageReport, type DamagedTyre, type DesignStats, type DriveInput, type Driver, type DriverState, type DrivingBody, type DrivingEvent, type DrivingWorld, type FuelModel, type RunOverOutcome, type RunOverRules, type SemiDriver, type SemiEvent, type SemiGround, type SemiInput, type SemiSimOptions, type SemiSimSpec, type SemiState, type SemiWheel, type SemiWorld, type StepResult, type Surface, type SurfaceOptions, type SurfaceRegistry, type VehicleCondition, bodyDamage, conditionFromDamage, createArcadeDriver, createSemiSimDriver, createSurfaces, defaultArcadeSpec, defaultFuelModel, defaultSemiSpec, defaultSurfaces, fuelRate, impactEnergy, runOver, semiSpecFromStats, speedLoss, surfaceGrip, vehicleCorners, vehicleDamageFromImpact };
|
package/dist/index.global.js
CHANGED
|
@@ -22,6 +22,7 @@ var GameVehiclesDriving = (() => {
|
|
|
22
22
|
var index_exports = {};
|
|
23
23
|
__export(index_exports, {
|
|
24
24
|
bodyDamage: () => bodyDamage,
|
|
25
|
+
conditionFromDamage: () => conditionFromDamage,
|
|
25
26
|
createArcadeDriver: () => createArcadeDriver,
|
|
26
27
|
createSemiSimDriver: () => createSemiSimDriver,
|
|
27
28
|
createSurfaces: () => createSurfaces,
|
|
@@ -343,6 +344,14 @@ var GameVehiclesDriving = (() => {
|
|
|
343
344
|
const t = rpm <= e.peakRpm ? 0.7 + 0.3 * clamp2((rpm - e.idleRpm) / (e.peakRpm - e.idleRpm), 0, 1) : 1 - 0.4 * ((rpm - e.peakRpm) / (e.redlineRpm - e.peakRpm));
|
|
344
345
|
return e.peakTorque * t;
|
|
345
346
|
};
|
|
347
|
+
var SLIDING_GRIP = 0.75;
|
|
348
|
+
var LOCKED_STEER = 0.15;
|
|
349
|
+
var AMBIENT_C = 25;
|
|
350
|
+
var BRAKE_FADE_FROM_C = 350;
|
|
351
|
+
var BRAKE_FADE_TO_C = 650;
|
|
352
|
+
var BRAKE_FADED = 0.5;
|
|
353
|
+
var BRAKE_HEAT_CAPACITY = 3;
|
|
354
|
+
var BRAKE_COOL_S = 60;
|
|
346
355
|
function createSemiSimDriver(specification = {}, options = {}) {
|
|
347
356
|
const spec = { ...defaultSemiSpec, ...specification };
|
|
348
357
|
const surfaces = options.surfaces ?? createSurfaces();
|
|
@@ -408,6 +417,7 @@ var GameVehiclesDriving = (() => {
|
|
|
408
417
|
const mass = baseMass + cargo;
|
|
409
418
|
const engineHealth = clamp2(cond.engine ?? 1, 0, 1);
|
|
410
419
|
const suspensionHealth = clamp2(cond.suspension ?? 1, 0, 1);
|
|
420
|
+
const brakeHealth = clamp2(cond.brakes ?? 1, 0, 1);
|
|
411
421
|
const inertia = (spec.yawInertia ?? baseMass * (wheelbase * wheelbase + track * track) / 12) * (mass / baseMass);
|
|
412
422
|
const pitchInertia = mass * (wheelbase * wheelbase + 1) / 12;
|
|
413
423
|
const rollInertia = mass * (track * track + 1) / 12;
|
|
@@ -492,6 +502,9 @@ var GameVehiclesDriving = (() => {
|
|
|
492
502
|
sumNA += load * w.x;
|
|
493
503
|
sumNB += load * w.z;
|
|
494
504
|
}
|
|
505
|
+
const brakeHeat = state.brakeHeat ?? AMBIENT_C;
|
|
506
|
+
const fade = 1 - clamp2((brakeHeat - BRAKE_FADE_FROM_C) / (BRAKE_FADE_TO_C - BRAKE_FADE_FROM_C), 0, 1) * (1 - BRAKE_FADED);
|
|
507
|
+
let brakeWork = 0;
|
|
495
508
|
let fFwd = 0;
|
|
496
509
|
let fRight = 0;
|
|
497
510
|
let torque = 0;
|
|
@@ -514,14 +527,17 @@ var GameVehiclesDriving = (() => {
|
|
|
514
527
|
let fl = 0;
|
|
515
528
|
if (driveWheels.some((d) => d.i === i)) fl += driveForceTotal / drivenCount;
|
|
516
529
|
const locked = handbrake && w.handbrake;
|
|
517
|
-
const brakeShare = spec.brakeForce * brakeInput * ws.n / loadSum;
|
|
530
|
+
const brakeShare = spec.brakeForce * brakeHealth * fade * brakeInput * ws.n / loadSum;
|
|
518
531
|
const moving = Math.abs(vl) > 0.05;
|
|
519
|
-
|
|
532
|
+
const lockedByBrake = spec.abs === false && moving && brakeShare > capacity;
|
|
533
|
+
if (locked || lockedByBrake) fl += moving ? -Math.sign(vl) * capacity * (lockedByBrake ? SLIDING_GRIP : 1) : 0;
|
|
520
534
|
else if (brakeShare > 0 && moving) fl += -Math.sign(vl) * brakeShare;
|
|
535
|
+
if (brakeShare > 0 && moving) brakeWork += Math.min(brakeShare, capacity) * Math.abs(vl) * dt;
|
|
521
536
|
const rolling = ws.bog && accelInput > 0 ? spec.bogResistance : spec.rolling * (ws.flat ? 6 : 1);
|
|
522
537
|
const alpha = Math.atan2(vc, Math.abs(vl) + 0.5);
|
|
523
538
|
let fc = -Math.tanh(spec.tyre.corneringStiffness * alpha) * capacity;
|
|
524
539
|
if (locked) fc *= 0.6;
|
|
540
|
+
if (lockedByBrake) fc *= LOCKED_STEER;
|
|
525
541
|
const total = Math.hypot(fl, fc);
|
|
526
542
|
let used = 1;
|
|
527
543
|
if (total > capacity && total > 0) used = capacity / total;
|
|
@@ -542,6 +558,7 @@ var GameVehiclesDriving = (() => {
|
|
|
542
558
|
const bogNow = bogging && Math.abs(state.u) < 1 && accelInput > 0;
|
|
543
559
|
if (bogNow && !state.bogged) events.push({ type: "bogged" });
|
|
544
560
|
state.bogged = bogNow;
|
|
561
|
+
state.brakeHeat = brakeHeat + brakeWork / (baseMass * BRAKE_HEAT_CAPACITY) - (brakeHeat - AMBIENT_C) * Math.min(1, dt / BRAKE_COOL_S);
|
|
545
562
|
fFwd += -spec.drag * state.u * Math.abs(state.u);
|
|
546
563
|
fRight += -spec.drag * state.w * Math.abs(state.w);
|
|
547
564
|
const du = fFwd / mass - state.yawRate * state.w;
|
|
@@ -594,7 +611,32 @@ var GameVehiclesDriving = (() => {
|
|
|
594
611
|
const thrust = torqueAtTop * lastRatio * spec.finalDrive * spec.efficiency / spec.wheelRadius;
|
|
595
612
|
const rollingForce = spec.rolling * body.mass * 9.81;
|
|
596
613
|
const drag = Math.max(0.01, (thrust - rollingForce) / (top * top));
|
|
597
|
-
|
|
614
|
+
const carRatio = defaultSemiSpec.brakeForce / (defaultSemiSpec.mass * 9.81);
|
|
615
|
+
const heavyShare = Math.max(0, Math.min(1, (body.mass - 2e3) / 8e3));
|
|
616
|
+
const brakeForce = base.brakeForce ?? body.mass * 9.81 * (carRatio + (0.6 - carRatio) * heavyShare);
|
|
617
|
+
return { ...spec, mass: body.mass, wheels, fourWheelDrive: driveAll, engine, gears, drag, brakeForce, tyre: { ...spec.tyre, friction: 0.8 + 0.03 * stats.handling } };
|
|
618
|
+
}
|
|
619
|
+
|
|
620
|
+
// src/semi/condition.ts
|
|
621
|
+
function conditionFromDamage(spec, report) {
|
|
622
|
+
const tyres = spec.wheels.map((wheel) => {
|
|
623
|
+
let best;
|
|
624
|
+
let distance = Infinity;
|
|
625
|
+
for (const tyre of report.tyres) {
|
|
626
|
+
const d = Math.hypot(tyre.x - wheel.x, tyre.z - wheel.z);
|
|
627
|
+
if (d < distance) {
|
|
628
|
+
distance = d;
|
|
629
|
+
best = tyre;
|
|
630
|
+
}
|
|
631
|
+
}
|
|
632
|
+
return best?.health ?? 1;
|
|
633
|
+
});
|
|
634
|
+
return {
|
|
635
|
+
tyres,
|
|
636
|
+
...report.brakes != null ? { brakes: report.brakes } : {},
|
|
637
|
+
...report.engine != null ? { engine: report.engine } : {},
|
|
638
|
+
...report.suspension != null ? { suspension: report.suspension } : {}
|
|
639
|
+
};
|
|
598
640
|
}
|
|
599
641
|
return __toCommonJS(index_exports);
|
|
600
642
|
})();
|