VehicleHelper

A helper class for creating realistic simulation of vehicles and suspensions.

Summary
VehicleHelperA helper class for creating realistic simulation of vehicles and suspensions.
Constructor
Preference DialogNone.
CommentsHere is a sample use of the VehicleHelper.
Functions
addWheel
setCoordinateSystem
setSteering
setBrake
applyEngineForce
delete

Constructor

VehicleHelper( molecule, tuning )

Parameters

molecule(object) the mesh molecule of the chasis.
tuning(object) properties of vehicle’s suspensions:
  • suspension_stiffness - (float) default to 10.88.
  • suspension_compression - (float) default to 1.83.
  • suspension_damping - (float) default to 0.28.
  • max_suspension_travel - (float) default to 500.
  • friction_slip - (float) default to 10.5.
  • max_suspension_force - (float) default to 6000.

Preference Dialog

None.

Comments

Here is a sample use of the VehicleHelper.

this.car = new VehicleHelper(this.r8, {
    suspension_stiffness: 10.88,
    suspension_compression: 1.83,
    suspension_damping: 0.28,
    max_suspension_travel: 500,
    friction_slip: 10.5,
    max_suspension_force: 6000});
// determine the connection point of each wheel
var dir = this.car.worldPosition.sub(ws[0].worldPosition);
var offsetfz = Math.abs(dir.z);
var offsetx = Math.abs(dir.x);
dir = this.r8.worldPosition.sub(ws[3].worldPosition);
var offsetrz = -Math.abs(dir.z);
var offsety = -dir.y;
var radius = ws[0].size.y * 0.42;
for (var i=0; i<4; i++)
{
    this.car.addWheel( ws[i],
           newVector3( i%2===0? offsetx : -offsetx,
                       offsety,
                       i<2? offsetfz : offsetrz),
           newVector3( 0, -1, 0),
           newVector3( -1, 0, 0),
           0.5,
           radius,
           i<2?true: false);
}

Functions

addWheel

addWheel(molecule, connection_point, wheel_direction, wheel_axle, suspension_rest_length, wheel_radius, is_front_wheel, tuning );

Destroy this joint.

Parameters

molecule(object) the mesh molecule of the wheel.
connection_point(vector3) point where wheel is connected to the chasis in the chasis’s coordinate space.
wheel_direction(vector3) the direction where wheels are pointing away from the chasis.  Normally (0, -1, 0).
wheel_axle(vector3) the direction of wheels’ rotational axis.  For z-forward vehicle, this is (-1, 0, 0).
suspension_rest_length(float) the length of suspension during rest.
wheel_radis(float) the radius of wheel.
is_front_wheel(bool) the wheel to be added is in front.
tuning(object) suspension tuning for individual wheel. default to the vehicle’s setting.

Returns

N/A

setCoordinateSystem

setCoordinateSystem( rightIndex, upIndex, forwardIndex );

Determine the vehicle’s orientation.  For z-forward, y-up vehicle, this is (0, 1, 2).

Parameters

rightIndex(int) axis index.  (0 for x-axis, 1 for y-axis, 2 for z-axis).
upIndex(int) axis index.
forwardIndex(int) axis index.

Returns

N/A

setSteering

setSteering( amount, wheel_index );

Specifies the steering amount for each wheel by index.

Parameters

amount(float) steering amount. positive and negative values for opposite directions.
wheel_index(int) wheel index is given by the order they were added (zero-based).

Returns

N/A

setBrake

setBrake( amount, wheel_index );

Specifies the braking force applied to each wheel by index.

Parameters

amount(float) braking force.
wheel_index(int) wheel index is given by the order they were added (zero-based).

Returns

N/A

applyEngineForce

applyEngineForce( force, wheel_index );

Applies engine force to wheels

Parameters

amount(float) acceleration force.
wheel_index(int, optional) wheel index is given by the order they were added (zero-based).  If none given, force is applied to all 4 wheels.

Returns

N/A

delete

delete();

Delete this vehicle rig.

Parameters

N/A

Returns

N/A

Close