@adatechnology/game-vehicles-proving 0.1.2 → 0.1.4

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.
@@ -182,7 +182,15 @@ var GameVehiclesProving = (() => {
182
182
  var clamp2 = (x, a, b) => Math.max(a, Math.min(b, x));
183
183
  var MAX_SUBSTEP = 1 / 240;
184
184
  var FLAT_BELOW = 0.2;
185
+ var RIM_RADIUS_SHARE = 0.7;
186
+ var RIM_FRICTION = 0.4;
187
+ var RIM_ROLLING = 0.25;
188
+ var FLAT_SAG = 0.05;
189
+ var FLAT_ROLLING = 6;
185
190
  var STALL_HEALTH = 0.3;
191
+ var CLUTCH_BITE = 0.7;
192
+ var STALL_RPM = 0.5;
193
+ var STALL_GAS = 0.35;
186
194
  var defaultSemiSpec = {
187
195
  mass: 1300,
188
196
  centreHeight: 0.5,
@@ -323,7 +331,14 @@ var GameVehiclesProving = (() => {
323
331
  const accelInput = reversing ? input.brake : input.throttle;
324
332
  const brakeInput = clamp2(reversing ? input.throttle : input.brake, 0, 1);
325
333
  const ratio = ratioOf(state.gear) * spec.finalDrive;
326
- state.rpm = clamp2(wheelRpm * ratio, spec.engine.idleRpm, spec.engine.redlineRpm + 200);
334
+ const engaged = input.clutch == null || state.gear === 0 ? 1 : 1 - clamp2(input.clutch, 0, 1);
335
+ const coupled = wheelRpm * ratio;
336
+ const free = spec.engine.idleRpm + clamp2(accelInput, 0, 1) * (spec.engine.redlineRpm * 0.7 - spec.engine.idleRpm);
337
+ state.rpm = clamp2(coupled * engaged + Math.max(coupled, free) * (1 - engaged), spec.engine.idleRpm, spec.engine.redlineRpm + 200);
338
+ if (input.clutch != null && state.gear !== 0 && state.engineOn && engaged > CLUTCH_BITE && coupled < spec.engine.idleRpm * STALL_RPM && accelInput < STALL_GAS) {
339
+ state.engineOn = false;
340
+ events.push({ type: "stall" });
341
+ }
327
342
  if (!state.engineOn || state.fuel <= 0) state.rpm = 0;
328
343
  let throttle = clamp2(accelInput, 0, 1);
329
344
  if (engineHealth < STALL_HEALTH && throttle > 0.8) {
@@ -334,12 +349,13 @@ var GameVehiclesProving = (() => {
334
349
  }
335
350
  throttle *= 0.5;
336
351
  } else stallWatch.throttleTime = 0;
337
- if (!state.engineOn && accelInput > 0 && Math.abs(state.u) < 0.5 && engineHealth >= STALL_HEALTH && state.fuel > 0) state.engineOn = true;
352
+ const starting = input.start ?? (accelInput > 0 && Math.abs(state.u) < 0.5);
353
+ if (!state.engineOn && starting && engineHealth >= STALL_HEALTH && state.fuel > 0) state.engineOn = true;
338
354
  if (state.fuel <= 0 && state.engineOn) {
339
355
  state.engineOn = false;
340
356
  events.push({ type: "out_of_fuel" });
341
357
  }
342
- const engineTorque = state.engineOn ? torqueAt(spec, state.rpm) * throttle * (0.55 + 0.45 * engineHealth) : 0;
358
+ const engineTorque = state.engineOn ? torqueAt(spec, state.rpm) * throttle * (0.55 + 0.45 * engineHealth) * clamp2(input.powerLimit ?? 1, 0, 1) * engaged : 0;
343
359
  const driveForceTotal = state.gear === 0 ? 0 : (reversing ? -1 : 1) * engineTorque * ratio * spec.efficiency / spec.wheelRadius;
344
360
  if (state.engineOn) {
345
361
  const burned = fuelRate(fuelModel, state.rpm / spec.engine.redlineRpm, throttle, cargo / baseMass, engineHealth) * dt;
@@ -357,19 +373,21 @@ var GameVehiclesProving = (() => {
357
373
  const wz = state.z - w.x * sn + w.z * cs;
358
374
  const ground = world.ground ? world.ground(wx, wz) : {};
359
375
  const surface = surfaces.get(contamination && contamination.left > 0 && surfaces.get(contamination.id).grip < surfaces.get(ground.surface ?? "dry_asphalt").grip ? contamination.id : ground.surface ?? "dry_asphalt");
376
+ const tyreHealth = cond.tyres ? clamp2(cond.tyres[i] ?? 1, 0, 1) : 1;
377
+ const rim = !!cond.rims?.[i];
378
+ const flat = rim || tyreHealth < FLAT_BELOW;
379
+ const radius = rim ? spec.rimRadius ?? spec.wheelRadius * RIM_RADIUS_SHARE : flat ? spec.wheelRadius - FLAT_SAG : spec.wheelRadius;
360
380
  const top = state.height + w.x * state.pitch - w.z * state.roll;
361
- const length = top - (ground.height ?? 0) - spec.wheelRadius;
381
+ const length = top - (ground.height ?? 0) - radius;
362
382
  const compression = ride - length;
363
383
  const rate = -(state.heightRate + w.x * state.pitchRate - w.z * state.rollRate);
364
384
  const k = spec.suspension.spring * (0.5 + 0.5 * suspensionHealth);
365
385
  const c = spec.suspension.damper * (0.5 + 0.5 * suspensionHealth);
366
386
  const load = Math.max(0, k * compression + c * rate);
367
- const tyreHealth = cond.tyres ? clamp2(cond.tyres[i] ?? 1, 0, 1) : 1;
368
- const flat = tyreHealth < FLAT_BELOW;
369
387
  const bog = !!surface.bogs && !spec.fourWheelDrive;
370
388
  if (bog) bogging = true;
371
- const grip = surfaceGrip(surface, state.u) * (flat ? 0.5 : 1);
372
- wheelState.push({ n: load, grip, surface: surface.id, bog, flat });
389
+ const grip = surfaceGrip(surface, state.u) * (rim ? RIM_FRICTION / spec.tyre.friction : flat ? 0.5 : 1);
390
+ wheelState.push({ n: load, grip, surface: surface.id, bog, flat, rim });
373
391
  sumN += load;
374
392
  sumNA += load * w.x;
375
393
  sumNB += load * w.z;
@@ -405,7 +423,7 @@ var GameVehiclesProving = (() => {
405
423
  if (locked || lockedByBrake) fl += moving ? -Math.sign(vl) * capacity * (lockedByBrake ? SLIDING_GRIP : 1) : 0;
406
424
  else if (brakeShare > 0 && moving) fl += -Math.sign(vl) * brakeShare;
407
425
  if (brakeShare > 0 && moving) brakeWork += Math.min(brakeShare, capacity) * Math.abs(vl) * dt;
408
- const rolling = ws.bog && accelInput > 0 ? spec.bogResistance : spec.rolling * (ws.flat ? 6 : 1);
426
+ const rolling = ws.bog && accelInput > 0 ? spec.bogResistance : ws.rim ? RIM_ROLLING : spec.rolling * (ws.flat ? FLAT_ROLLING : 1);
409
427
  const alpha = Math.atan2(vc, Math.abs(vl) + 0.5);
410
428
  let fc = -Math.tanh(spec.tyre.corneringStiffness * alpha) * capacity;
411
429
  if (locked) fc *= 0.6;