diff --git a/dist/cannon-es.cjs.js b/dist/cannon-es.cjs.js index fb720115a..d874006d1 100644 --- a/dist/cannon-es.cjs.js +++ b/dist/cannon-es.cjs.js @@ -6631,6 +6631,8 @@ class WheelInfo { dampingCompression: 10, dampingRelaxation: 10, frictionSlip: 10000, + forwardAcceleration: 1, + sideAcceleration: 1, steering: 0, rotation: 0, deltaRotation: 0, @@ -6664,6 +6666,8 @@ class WheelInfo { this.dampingCompression = options.dampingCompression; this.dampingRelaxation = options.dampingRelaxation; this.frictionSlip = options.frictionSlip; + this.forwardAcceleration = options.forwardAcceleration; + this.sideAcceleration = options.sideAcceleration; this.steering = 0; this.rotation = 0; this.deltaRotation = 0; @@ -7157,8 +7161,8 @@ class RaycastVehicle { const maximpSquared = maximp * maximpSide; wheel.forwardImpulse = rollingFriction; //wheelInfo.engineForce* timeStep; - const x = wheel.forwardImpulse * fwdFactor; - const y = wheel.sideImpulse * sideFactor; + const x = wheel.forwardImpulse * fwdFactor / wheel.forwardAcceleration; + const y = wheel.sideImpulse * sideFactor / wheel.sideAcceleration; const impulseSquared = x * x + y * y; wheel.sliding = false; diff --git a/dist/cannon-es.d.ts b/dist/cannon-es.d.ts index b32034681..381bccf80 100644 --- a/dist/cannon-es.d.ts +++ b/dist/cannon-es.d.ts @@ -1343,6 +1343,8 @@ declare module "objects/WheelInfo" { dampingCompression?: number; dampingRelaxation?: number; frictionSlip?: number; + forwardAcceleration?: number; + sideAcceleration?: number; steering?: number; rotation?: number; deltaRotation?: number; @@ -1382,6 +1384,8 @@ declare module "objects/WheelInfo" { dampingCompression: number; dampingRelaxation: number; frictionSlip: number; + forwardAcceleration: number; + sideAcceleration: number; steering: number; rotation: number; deltaRotation: number; diff --git a/dist/cannon-es.js b/dist/cannon-es.js index 1956060ab..2bd644409 100644 --- a/dist/cannon-es.js +++ b/dist/cannon-es.js @@ -6627,6 +6627,8 @@ class WheelInfo { dampingCompression: 10, dampingRelaxation: 10, frictionSlip: 10000, + forwardAcceleration: 1, + sideAcceleration: 1, steering: 0, rotation: 0, deltaRotation: 0, @@ -6660,6 +6662,8 @@ class WheelInfo { this.dampingCompression = options.dampingCompression; this.dampingRelaxation = options.dampingRelaxation; this.frictionSlip = options.frictionSlip; + this.forwardAcceleration = options.forwardAcceleration; + this.sideAcceleration = options.sideAcceleration; this.steering = 0; this.rotation = 0; this.deltaRotation = 0; @@ -7153,8 +7157,8 @@ class RaycastVehicle { const maximpSquared = maximp * maximpSide; wheel.forwardImpulse = rollingFriction; //wheelInfo.engineForce* timeStep; - const x = wheel.forwardImpulse * fwdFactor; - const y = wheel.sideImpulse * sideFactor; + const x = wheel.forwardImpulse * fwdFactor / wheel.forwardAcceleration; + const y = wheel.sideImpulse * sideFactor / wheel.sideAcceleration; const impulseSquared = x * x + y * y; wheel.sliding = false; diff --git a/examples/raycast_vehicle.html b/examples/raycast_vehicle.html index 78922b47d..bfaf60936 100644 --- a/examples/raycast_vehicle.html +++ b/examples/raycast_vehicle.html @@ -34,7 +34,7 @@ directionLocal: new CANNON.Vec3(0, -1, 0), suspensionStiffness: 30, suspensionRestLength: 0.3, - frictionSlip: 5, + frictionSlip: 1.4, dampingRelaxation: 2.3, dampingCompression: 4.4, maxSuspensionForce: 100000, diff --git a/src/objects/RaycastVehicle.ts b/src/objects/RaycastVehicle.ts index 4af20ccc5..e3f2f6f7c 100644 --- a/src/objects/RaycastVehicle.ts +++ b/src/objects/RaycastVehicle.ts @@ -504,8 +504,8 @@ export class RaycastVehicle { wheel.forwardImpulse = rollingFriction //wheelInfo.engineForce* timeStep; - const x = wheel.forwardImpulse * fwdFactor - const y = wheel.sideImpulse * sideFactor + const x = wheel.forwardImpulse * fwdFactor / wheel.forwardAcceleration + const y = wheel.sideImpulse * sideFactor / wheel.sideAcceleration const impulseSquared = x * x + y * y diff --git a/src/objects/WheelInfo.ts b/src/objects/WheelInfo.ts index 0048738b8..9edc5a94f 100644 --- a/src/objects/WheelInfo.ts +++ b/src/objects/WheelInfo.ts @@ -18,6 +18,8 @@ export type WheelInfoOptions = { dampingCompression?: number dampingRelaxation?: number frictionSlip?: number + forwardAcceleration?: number + sideAcceleration?: number steering?: number rotation?: number deltaRotation?: number @@ -93,6 +95,8 @@ export class WheelInfo { dampingCompression: number dampingRelaxation: number frictionSlip: number + forwardAcceleration: number + sideAcceleration: number steering: number rotation: number // Rotation value, in radians. deltaRotation: number @@ -128,6 +132,8 @@ export class WheelInfo { dampingCompression: 10, dampingRelaxation: 10, frictionSlip: 10000, + forwardAcceleration: 1, + sideAcceleration: 1, steering: 0, rotation: 0, deltaRotation: 0, @@ -162,6 +168,8 @@ export class WheelInfo { this.dampingCompression = options.dampingCompression! this.dampingRelaxation = options.dampingRelaxation! this.frictionSlip = options.frictionSlip! + this.forwardAcceleration = options.forwardAcceleration! + this.sideAcceleration = options.sideAcceleration! this.steering = 0 this.rotation = 0 this.deltaRotation = 0