@@ -377,30 +377,35 @@ namespace gdjs {
377
377
// );
378
378
379
379
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' )
404
409
) ;
405
410
406
411
// console.log(forward, right, brake, handBrake);
@@ -672,15 +677,16 @@ namespace gdjs {
672
677
const { behavior } = physics3D ;
673
678
const { owner3D, _sharedData } = this . vehicleBehavior ;
674
679
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 =
679
681
( owner3D . getWidth ( ) / 2 ) * _sharedData . worldInvScale ;
680
- const wheelOffsetY =
682
+ const halfVehicleHeight =
681
683
( owner3D . getHeight ( ) / 2 ) * _sharedData . worldInvScale ;
682
- const wheelOffsetZ =
684
+ const halfVehicleDepth =
683
685
( owner3D . getDepth ( ) / 2 ) * _sharedData . worldInvScale ;
686
+
687
+ const wheelOffsetX = halfVehicleWidth ;
688
+ const wheelOffsetY = halfVehicleHeight ;
689
+ const wheelOffsetZ = halfVehicleDepth ;
684
690
const wheelRadius = wheelOffsetZ ;
685
691
const wheelWidth = wheelOffsetZ / 3 ;
686
692
const suspensionMinLength = wheelOffsetZ / 4 ;
@@ -696,13 +702,24 @@ namespace gdjs {
696
702
const BL_WHEEL = 2 ;
697
703
const BR_WHEEL = 3 ;
698
704
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 ( ) ;
702
719
703
720
// Create car body
704
721
const carBodySettings = new Jolt . BodyCreationSettings (
705
- shape ,
722
+ carShape ,
706
723
this . vehicleBehavior . getPhysicsPosition (
707
724
_sharedData . getRVec3 ( 0 , 0 , 0 )
708
725
) ,
@@ -723,7 +740,7 @@ namespace gdjs {
723
740
// Create vehicle constraint
724
741
const vehicle = new Jolt . VehicleConstraintSettings ( ) ;
725
742
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 ) ;
727
744
vehicle . mMaxPitchRollAngle = gdjs . toRad ( 60.0 ) ;
728
745
vehicle . mWheels . clear ( ) ;
729
746
const mWheels : Array < Jolt . WheelSettingsWV > = [ ] ;
0 commit comments