Skip to content

Commit 80e0056

Browse files
committed
Fix car forward direction.
1 parent c73b0d6 commit 80e0056

File tree

1 file changed

+52
-35
lines changed

1 file changed

+52
-35
lines changed

Extensions/Physics3DBehavior/PhysicsVehicle3DRuntimeBehavior.ts

+52-35
Original file line numberDiff line numberDiff line change
@@ -377,30 +377,35 @@ namespace gdjs {
377377
// );
378378

379379
console.log(
380-
vec3ToString(
381-
this._vehicleController
382-
.GetConstraint()
383-
.GetWheel(0)
384-
.GetContactPosition()
385-
),
386-
vec3ToString(
387-
this._vehicleController
388-
.GetConstraint()
389-
.GetWheel(1)
390-
.GetContactPosition()
391-
),
392-
vec3ToString(
393-
this._vehicleController
394-
.GetConstraint()
395-
.GetWheel(2)
396-
.GetContactPosition()
397-
),
398-
vec3ToString(
399-
this._vehicleController
400-
.GetConstraint()
401-
.GetWheel(3)
402-
.GetContactPosition()
403-
)
380+
[
381+
"Car center",
382+
vec3ToString(carBody.GetPosition()),
383+
"Wheels",
384+
vec3ToString(
385+
this._vehicleController
386+
.GetConstraint()
387+
.GetWheel(0)
388+
.GetContactPosition()
389+
),
390+
vec3ToString(
391+
this._vehicleController
392+
.GetConstraint()
393+
.GetWheel(1)
394+
.GetContactPosition()
395+
),
396+
vec3ToString(
397+
this._vehicleController
398+
.GetConstraint()
399+
.GetWheel(2)
400+
.GetContactPosition()
401+
),
402+
vec3ToString(
403+
this._vehicleController
404+
.GetConstraint()
405+
.GetWheel(3)
406+
.GetContactPosition()
407+
),
408+
].join('\n')
404409
);
405410

406411
// console.log(forward, right, brake, handBrake);
@@ -672,15 +677,16 @@ namespace gdjs {
672677
const { behavior } = physics3D;
673678
const { owner3D, _sharedData } = this.vehicleBehavior;
674679

675-
// TODO Use OffsetCenterOfMassShapeSettings to allow to set a custom center of mass in createShape.
676-
const shape = behavior.createShape();
677-
678-
const wheelOffsetX =
680+
const halfVehicleWidth =
679681
(owner3D.getWidth() / 2) * _sharedData.worldInvScale;
680-
const wheelOffsetY =
682+
const halfVehicleHeight =
681683
(owner3D.getHeight() / 2) * _sharedData.worldInvScale;
682-
const wheelOffsetZ =
684+
const halfVehicleDepth =
683685
(owner3D.getDepth() / 2) * _sharedData.worldInvScale;
686+
687+
const wheelOffsetX = halfVehicleWidth;
688+
const wheelOffsetY = halfVehicleHeight;
689+
const wheelOffsetZ = halfVehicleDepth;
684690
const wheelRadius = wheelOffsetZ;
685691
const wheelWidth = wheelOffsetZ / 3;
686692
const suspensionMinLength = wheelOffsetZ / 4;
@@ -696,13 +702,24 @@ namespace gdjs {
696702
const BL_WHEEL = 2;
697703
const BR_WHEEL = 3;
698704

699-
const vehicleMass = 1500.0;
700-
const maxEngineTorque = 500.0;
701-
const clutchStrength = 10.0;
705+
const vehicleMass = 1500;
706+
const maxEngineTorque = 500;
707+
const clutchStrength = 10;
708+
709+
// TODO Use OffsetCenterOfMassShapeSettings to allow to set a custom center of mass in createShape.
710+
//const carShape = behavior.createShape();
711+
712+
const carShapeSettings = new Jolt.OffsetCenterOfMassShapeSettings(
713+
new Jolt.Vec3(0, 0, -halfVehicleDepth),
714+
new Jolt.BoxShapeSettings(
715+
new Jolt.Vec3(halfVehicleWidth, halfVehicleHeight, halfVehicleDepth)
716+
)
717+
);
718+
const carShape = carShapeSettings.Create().Get();
702719

703720
// Create car body
704721
const carBodySettings = new Jolt.BodyCreationSettings(
705-
shape,
722+
carShape,
706723
this.vehicleBehavior.getPhysicsPosition(
707724
_sharedData.getRVec3(0, 0, 0)
708725
),
@@ -723,7 +740,7 @@ namespace gdjs {
723740
// Create vehicle constraint
724741
const vehicle = new Jolt.VehicleConstraintSettings();
725742
vehicle.mUp = new Jolt.Vec3(0, 0, 1);
726-
vehicle.mForward = new Jolt.Vec3(0, 0, 1);
743+
vehicle.mForward = new Jolt.Vec3(1, 0, 0);
727744
vehicle.mMaxPitchRollAngle = gdjs.toRad(60.0);
728745
vehicle.mWheels.clear();
729746
const mWheels: Array<Jolt.WheelSettingsWV> = [];

0 commit comments

Comments
 (0)