2
2
3
3
// TODO Remove
4
4
const vec3ToString = ( vec3 : Jolt . RVec3 ) =>
5
- Math . round ( vec3 . GetX ( ) * 100 ) +
5
+ vec3 . GetX ( ) . toFixed ( 3 ) +
6
6
' ' +
7
- Math . round ( vec3 . GetY ( ) * 100 ) +
7
+ vec3 . GetY ( ) . toFixed ( 3 ) +
8
8
' ' +
9
- Math . round ( vec3 . GetZ ( ) * 100 ) ;
9
+ vec3 . GetZ ( ) . toFixed ( 3 ) ;
10
10
11
11
namespace gdjs {
12
12
interface PhysicsVehicle3DNetworkSyncDataType {
@@ -329,13 +329,13 @@ namespace gdjs {
329
329
forward = this . _hasPressedForwardKey
330
330
? 1.0
331
331
: this . _hasPressedBackwardKey
332
- ? - 1.0
333
- : 0.0 ;
332
+ ? - 1.0
333
+ : 0.0 ;
334
334
right = this . _hasPressedRightKey
335
335
? 1.0
336
336
: this . _hasPressedLeftKey
337
- ? - 1.0
338
- : 0.0 ;
337
+ ? - 1.0
338
+ : 0.0 ;
339
339
340
340
if ( this . previousForward < 0 !== forward < 0 ) {
341
341
const velocity = carBody
@@ -378,9 +378,21 @@ namespace gdjs {
378
378
379
379
console . log (
380
380
[
381
- " Car center" ,
381
+ ' Car center' ,
382
382
vec3ToString ( carBody . GetPosition ( ) ) ,
383
- "Wheels" ,
383
+ 'Mass center' ,
384
+ vec3ToString ( carBody . GetCenterOfMassPosition ( ) ) ,
385
+ 'Mass' ,
386
+ 1 / carBody . GetMotionProperties ( ) . GetInverseMass ( ) ,
387
+ 'Speed' ,
388
+ ( carBody
389
+ . GetRotation ( )
390
+ . InverseRotate ( carBody . GetLinearVelocity ( ) )
391
+ . GetX ( ) *
392
+ 60 *
393
+ 60 ) /
394
+ 1000 ,
395
+ 'Wheels' ,
384
396
vec3ToString (
385
397
this . _vehicleController
386
398
. GetConstraint ( )
@@ -410,7 +422,7 @@ namespace gdjs {
410
422
411
423
// console.log(forward, right, brake, handBrake);
412
424
413
- this . _vehicleController . SetDriverInput ( forward , right , brake , handBrake ) ;
425
+ this . _vehicleController . SetDriverInput ( forward , - right , brake , handBrake ) ;
414
426
if (
415
427
right !== 0.0 ||
416
428
forward !== 0.0 ||
@@ -675,24 +687,23 @@ namespace gdjs {
675
687
return null ;
676
688
}
677
689
const { behavior } = physics3D ;
678
- const { owner3D , _sharedData } = this . vehicleBehavior ;
690
+ const { _sharedData } = this . vehicleBehavior ;
679
691
680
- const halfVehicleWidth =
681
- ( owner3D . getWidth ( ) / 2 ) * _sharedData . worldInvScale ;
682
- const halfVehicleHeight =
683
- ( owner3D . getHeight ( ) / 2 ) * _sharedData . worldInvScale ;
684
- const halfVehicleDepth =
685
- ( owner3D . getDepth ( ) / 2 ) * _sharedData . worldInvScale ;
692
+ const halfVehicleWidth = behavior . _shapeHalfWidth ;
693
+ const halfVehicleHeight = behavior . _shapeHalfHeight ;
694
+ const halfVehicleDepth = behavior . _shapeHalfDepth ;
695
+
696
+ console . log ( halfVehicleWidth , halfVehicleHeight , halfVehicleDepth ) ;
686
697
687
698
const wheelOffsetX = halfVehicleWidth ;
688
699
const wheelOffsetY = halfVehicleHeight ;
689
- const wheelOffsetZ = halfVehicleDepth ;
690
- const wheelRadius = wheelOffsetZ ;
691
- const wheelWidth = wheelOffsetZ / 3 ;
692
- const suspensionMinLength = wheelOffsetZ / 4 ;
693
- const suspensionMaxLength = 2 * suspensionMinLength ;
700
+ const wheelOffsetZ = 0 ;
701
+ const wheelRadius = halfVehicleDepth ;
702
+ const wheelWidth = halfVehicleDepth / 3 ;
703
+ const suspensionMinLength = wheelRadius ;
704
+ const suspensionMaxLength = 1.5 * suspensionMinLength ;
694
705
const maxSteerAngle = gdjs . toRad ( 30 ) ;
695
- const fourWheelDrive = true ;
706
+ const fourWheelDrive = false ;
696
707
const frontBackLimitedSlipRatio = 1.4 ;
697
708
const leftRightLimitedSlipRatio = 1.4 ;
698
709
const antiRollbar = true ;
@@ -706,16 +717,7 @@ namespace gdjs {
706
717
const maxEngineTorque = 500 ;
707
718
const clutchStrength = 10 ;
708
719
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 ( ) ;
720
+ const carShape = behavior . createShape ( ) ;
719
721
720
722
// Create car body
721
723
const carBodySettings = new Jolt . BodyCreationSettings (
@@ -790,10 +792,18 @@ namespace gdjs {
790
792
mWheels . forEach ( ( wheelS ) => {
791
793
wheelS . mWheelUp = new Jolt . Vec3 ( 0 , 0 , 1 ) ;
792
794
wheelS . mWheelForward = new Jolt . Vec3 ( 1 , 0 , 0 ) ;
795
+ wheelS . mSuspensionDirection = new Jolt . Vec3 ( 0 , 0 , - 1 ) ;
796
+ wheelS . mSteeringAxis = new Jolt . Vec3 ( 0 , 0 , 1 ) ;
793
797
wheelS . mRadius = wheelRadius ;
794
798
wheelS . mWidth = wheelWidth ;
795
799
wheelS . mSuspensionMinLength = suspensionMinLength ;
796
800
wheelS . mSuspensionMaxLength = suspensionMaxLength ;
801
+ // wheelS.mLongitudinalFriction.Clear();
802
+ // wheelS.mLongitudinalFriction.AddPoint(0, 1);
803
+ // wheelS.mLongitudinalFriction.AddPoint(1, 1);
804
+ // wheelS.mLateralFriction.Clear();
805
+ // wheelS.mLateralFriction.AddPoint(0, 1.2);
806
+ // wheelS.mLateralFriction.AddPoint(90, 1.2);
797
807
} ) ;
798
808
799
809
const controllerSettings = new Jolt . WheeledVehicleControllerSettings ( ) ;
@@ -856,8 +866,8 @@ namespace gdjs {
856
866
// behavior.getBodyLayer(),
857
867
// 0.05,
858
868
// )
859
- // );
860
-
869
+ // );
870
+
861
871
constraint . ResetGravityOverride ( ) ;
862
872
_sharedData . physicsSystem . AddConstraint ( constraint ) ;
863
873
this . vehicleBehavior . _vehicleController = Jolt . castObject (
0 commit comments