Skip to content

Commit abc6de9

Browse files
committed
Use the default gear ratios.
1 parent 4ca6e66 commit abc6de9

File tree

1 file changed

+33
-26
lines changed

1 file changed

+33
-26
lines changed

Extensions/Physics3DBehavior/PhysicsVehicle3DRuntimeBehavior.ts

+33-26
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,9 @@ namespace gdjs {
4545
_sharedData: gdjs.Physics3DSharedData;
4646
private _destroyedDuringFrameLogic: boolean = false;
4747

48-
_steerAngleMax = 30;
49-
private _steerAngularVelocity: float = 30;
48+
_steerAngleMax = 70;
49+
private _beginningSteerAngularVelocity: float = 35;
50+
private _endSteerAngularVelocity: float = 5;
5051
private _currentSteerRatio: float = 0;
5152

5253
private _hasPressedForwardKey: boolean = false;
@@ -256,22 +257,28 @@ namespace gdjs {
256257
? -1.0
257258
: 0.0;
258259

259-
if (!this._hasPressedLeftKey && !this._hasPressedRightKey) {
260+
if (this._hasPressedLeftKey === this._hasPressedRightKey) {
260261
this._currentSteerRatio = 0;
261-
}
262-
if (this._hasPressedLeftKey) {
263-
// Avoid to much latency when changing of direction
264-
this._currentSteerRatio = Math.min(0, this._currentSteerRatio);
265-
this._currentSteerRatio -=
266-
(this._steerAngularVelocity * timeDelta) / this._steerAngleMax;
267-
this._currentSteerRatio = Math.max(-1, this._currentSteerRatio);
268-
}
269-
if (this._hasPressedRightKey) {
270-
// Avoid to much latency when changing of direction
271-
this._currentSteerRatio = Math.max(0, this._currentSteerRatio);
272-
this._currentSteerRatio +=
273-
(this._steerAngularVelocity * timeDelta) / this._steerAngleMax;
274-
this._currentSteerRatio = Math.min(1, this._currentSteerRatio);
262+
} else {
263+
const steerAngularVelocity = gdjs.evtTools.common.lerp(
264+
this._beginningSteerAngularVelocity,
265+
this._endSteerAngularVelocity,
266+
this._currentSteerRatio
267+
);
268+
if (this._hasPressedLeftKey) {
269+
// Avoid to much latency when changing of direction
270+
this._currentSteerRatio = Math.min(0, this._currentSteerRatio);
271+
this._currentSteerRatio -=
272+
(steerAngularVelocity * timeDelta) / this._steerAngleMax;
273+
this._currentSteerRatio = Math.max(-1, this._currentSteerRatio);
274+
}
275+
if (this._hasPressedRightKey) {
276+
// Avoid to much latency when changing of direction
277+
this._currentSteerRatio = Math.max(0, this._currentSteerRatio);
278+
this._currentSteerRatio +=
279+
(steerAngularVelocity * timeDelta) / this._steerAngleMax;
280+
this._currentSteerRatio = Math.min(1, this._currentSteerRatio);
281+
}
275282
}
276283

277284
if (this.previousForward < 0 !== forward < 0) {
@@ -513,7 +520,7 @@ namespace gdjs {
513520
const BR_WHEEL = 3;
514521

515522
const vehicleMass = 1500;
516-
const maxEngineTorque = 3000;
523+
const maxEngineTorque = 1.5 * 3000;
517524
const clutchStrength = 10;
518525

519526
const carShape = behavior.createShape();
@@ -607,16 +614,16 @@ namespace gdjs {
607614

608615
const controllerSettings = new Jolt.WheeledVehicleControllerSettings();
609616
controllerSettings.mEngine.mMaxTorque = maxEngineTorque;
610-
controllerSettings.mEngine.mMaxRPM = 1000;
617+
// controllerSettings.mEngine.mMaxRPM = 1000;
611618
controllerSettings.mEngine.mInertia = 0.01;
612-
controllerSettings.mEngine.mNormalizedTorque.Clear();
613-
controllerSettings.mEngine.mNormalizedTorque.AddPoint(0, 1);
614-
controllerSettings.mEngine.mNormalizedTorque.AddPoint(1, 1);
619+
// controllerSettings.mEngine.mNormalizedTorque.Clear();
620+
// controllerSettings.mEngine.mNormalizedTorque.AddPoint(0, 1);
621+
// controllerSettings.mEngine.mNormalizedTorque.AddPoint(1, 1);
615622
controllerSettings.mTransmission.mClutchStrength = clutchStrength;
616-
controllerSettings.mTransmission.mGearRatios.clear();
617-
controllerSettings.mTransmission.mGearRatios.push_back(1);
618-
controllerSettings.mTransmission.mReverseGearRatios.clear();
619-
controllerSettings.mTransmission.mReverseGearRatios.push_back(-1);
623+
// controllerSettings.mTransmission.mGearRatios.clear();
624+
// controllerSettings.mTransmission.mGearRatios.push_back(1);
625+
// controllerSettings.mTransmission.mReverseGearRatios.clear();
626+
// controllerSettings.mTransmission.mReverseGearRatios.push_back(-1);
620627

621628
vehicle.mController = controllerSettings;
622629

0 commit comments

Comments
 (0)