API Docs for: 0.7.1
Show:

TopDownVehicle Class

Constructor

TopDownVehicle

(
  • chassisBody
  • [options]
)

Parameters:

  • chassisBody Body

    A dynamic body, already added to the world.

  • [options] Object optional

Example:

// Create a dynamic body for the chassis
        var chassisBody = new Body({
            mass: 1
        });
        var boxShape = new Box({ width: 0.5, height: 1 });
        chassisBody.addShape(boxShape);
        world.addBody(chassisBody);
        
        // Create the vehicle
        var vehicle = new TopDownVehicle(chassisBody);
        
        // Add one front wheel and one back wheel - we don't actually need four :)
        var frontWheel = vehicle.addWheel({
            localPosition: [0, 0.5] // front
        });
        frontWheel.setSideFriction(4);
        
        // Back wheel
        var backWheel = vehicle.addWheel({
            localPosition: [0, -0.5] // back
        });
        backWheel.setSideFriction(3); // Less side friction on back wheel makes it easier to drift
        vehicle.addToWorld(world);
        
        // Steer value zero means straight forward. Positive is left and negative right.
        frontWheel.steerValue = Math.PI / 16;
        
        // Engine force forward
        backWheel.engineForce = 10;
        backWheel.setBrakeForce(0);
        

Methods

addToWorld

(
  • world
)

Parameters:

addWheel

(
  • [wheelOptions]
)
WheelConstraint

Parameters:

  • [wheelOptions] Object optional

Returns:

removeFromWorld

(
  • world
)

Parameters:

update

()

Properties

chassisBody

Body

wheels

Array