Skip to content

Commit

Permalink
Physics & Suspension (#994)
Browse files Browse the repository at this point in the history
  • Loading branch information
HunterBarclay authored Jun 26, 2024
2 parents 7f9e87c + 1031d57 commit 523eebb
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
17 changes: 9 additions & 8 deletions fission/src/systems/physics/PhysicsSystem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ const COUNT_OBJECT_LAYERS = 10
export const SIMULATION_PERIOD = 1.0 / 120.0
const STANDARD_SUB_STEPS = 3

// Friction constants
const FLOOR_FRICTION = 0.7;
const SUSPENSION_MIN_FACTOR = 0.1;
const SUSPENSION_MAX_FACTOR = 0.3;

/**
* The PhysicsSystem handles all Jolt Phyiscs interactions within Synthesis.
* This system can create physical representations of objects such as Robots,
Expand Down Expand Up @@ -68,8 +73,10 @@ class PhysicsSystem extends WorldSystem {
new THREE.Vector3(0.0, -2.0, 0.0),
undefined
)
ground.SetFriction(FLOOR_FRICTION);
this._joltBodyInterface.AddBody(ground.GetID(), JOLT.EActivation_Activate)
}


/**
* TEMPORARY
Expand Down Expand Up @@ -449,16 +456,10 @@ class PhysicsSystem extends WorldSystem {
wheelSettings.mMaxHandBrakeTorque = 0.0
wheelSettings.mRadius = radius * 1.05
wheelSettings.mWidth = 0.1
wheelSettings.mSuspensionMinLength = 0.0000003
wheelSettings.mSuspensionMaxLength = 0.0000006
wheelSettings.mSuspensionMinLength = radius * SUSPENSION_MIN_FACTOR
wheelSettings.mSuspensionMaxLength = radius * SUSPENSION_MAX_FACTOR
wheelSettings.mInertia = 1

const friction = new JOLT.LinearCurve()
friction.Clear()
friction.AddPoint(1, 1)
friction.AddPoint(0, 1)
wheelSettings.mLongitudinalFriction = friction

const vehicleSettings = new JOLT.VehicleConstraintSettings()

vehicleSettings.mWheels.clear()
Expand Down
5 changes: 5 additions & 0 deletions fission/src/systems/simulation/driver/WheelDriver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ import Jolt from "@barclah/jolt-physics"
import Driver from "./Driver"
import JOLT from "@/util/loading/JoltSyncLoader"

const LATERIAL_FRICTION = 0.6;
const LONGITUDINAL_FRICTION = 0.8;

class WheelDriver extends Driver {
private _constraint: Jolt.VehicleConstraint
private _wheel: Jolt.WheelWV
Expand All @@ -22,6 +25,8 @@ class WheelDriver extends Driver {

this._constraint = constraint;
this._wheel = JOLT.castObject(this._constraint.GetWheel(0), JOLT.WheelWV);
this._wheel.set_mCombinedLateralFriction(LATERIAL_FRICTION);
this._wheel.set_mCombinedLongitudinalFriction(LONGITUDINAL_FRICTION);
}

public Update(_: number): void {
Expand Down

0 comments on commit 523eebb

Please sign in to comment.