public class PhysicsVehicle extends PhysicsRigidBody
btRaycastVehicle.
The wheels of a PhysicsVehicle aren't collision objects, so the vehicle's ignore list doesn't affect them.
From Bullet manual:
For arcade style vehicle simulations, it is recommended to use the simplified
Bullet vehicle model as provided in btRaycastVehicle. Instead of simulation
each wheel and chassis as separate rigid bodies, connected by constraints, it
uses a simplified model. This simplified model has many benefits, and is
widely used in commercial driving games.
The entire vehicle is represented as a single rigid body, the chassis. The collision detection of the wheels is approximated by ray casts, and the tire friction is a basic anisotropic friction model.
| Modifier and Type | Field and Description |
|---|---|
static java.util.logging.Logger |
logger3
message logger for this class
|
logger2, massmassForStaticCOLLISION_GROUP_01, COLLISION_GROUP_02, COLLISION_GROUP_03, COLLISION_GROUP_04, COLLISION_GROUP_05, COLLISION_GROUP_06, COLLISION_GROUP_07, COLLISION_GROUP_08, COLLISION_GROUP_09, COLLISION_GROUP_10, COLLISION_GROUP_11, COLLISION_GROUP_12, COLLISION_GROUP_13, COLLISION_GROUP_14, COLLISION_GROUP_15, COLLISION_GROUP_16, COLLISION_GROUP_NONE, loggerloggerN| Constructor and Description |
|---|
PhysicsVehicle(CollisionShape shape)
Instantiate a responsive vehicle with the specified CollisionShape and
mass=1.
|
PhysicsVehicle(CollisionShape shape,
float mass)
Instantiate a responsive vehicle with the specified CollisionShape and
mass.
|
| Modifier and Type | Method and Description |
|---|---|
void |
accelerate(float force)
Apply the specified engine force to each wheel.
|
void |
accelerate(int wheelIndex,
float force)
Apply the specified engine force to the indexed wheel.
|
VehicleWheel |
addWheel(Vector3f connectionPoint,
Vector3f direction,
Vector3f axle,
float suspensionRestLength,
float wheelRadius,
boolean isFrontWheel)
Add a wheel to this vehicle.
|
void |
brake(float impulse)
Apply the specified brake impulse to all wheels.
|
void |
brake(int wheelIndex,
float impulse)
Apply the specified brake impulse to the indexed wheel.
|
float |
castRay(int wheelIndex)
Compute depth for the indexed wheel by raycasting.
|
void |
createVehicle(PhysicsSpace space)
Used internally, creates the controller when the vehicle is added to a
PhysicsSpace.
|
int |
forwardAxisIndex()
Determine the index of this vehicle's forward axis.
|
VehicleController |
getController()
Access this vehicle's controller.
|
float |
getCurrentVehicleSpeedKmHour()
Determine this vehicle's forward velocity as of the previous simulation
step.
|
Vector3f |
getForwardVector(Vector3f storeResult)
Determine this vehicle's forward direction.
|
float |
getFrictionSlip()
Determine the initial friction for new wheels.
|
float |
getMaxSuspensionForce()
Determine the initial maximum suspension force for new wheels.
|
float |
getMaxSuspensionTravelCm()
Determine the initial maximum suspension travel distance for new wheels.
|
int |
getNumWheels()
Count the number of wheels on this vehicle.
|
float |
getSuspensionCompression()
Determine the initial damping (when the suspension is compressed) for new
wheels.
|
float |
getSuspensionDamping()
Determine the initial damping (when the suspension is expanded) for new
wheels.
|
float |
getSuspensionStiffness()
Determine the initial suspension stiffness for new wheels.
|
VehicleTuning |
getTuning()
Access the tuning parameters applied when a wheel is created.
|
long |
getVehicleId()
Used internally.
|
VehicleWheel |
getWheel(int wheelIndex)
Access the indexed wheel of this vehicle.
|
protected void |
postRebuild()
Invoked during a rebuild after the native object is created.
|
void |
removeWheel(int wheelIndex)
Remove a wheel.
|
void |
resetSuspension()
Reset this vehicle's suspension.
|
int |
rightAxisIndex()
Determine the index of this vehicle's right-side axis.
|
void |
setFrictionSlip(float frictionSlip)
Alter the initial friction for new wheels.
|
void |
setFrictionSlip(int wheelIndex,
float frictionSlip)
Alter the friction of the indexed wheel.
|
void |
setMaxSuspensionForce(float maxSuspensionForce)
Alter the initial maximum suspension force for new wheels.
|
void |
setMaxSuspensionForce(int wheelIndex,
float maxSuspensionForce)
Alter the maximum suspension force for the specified wheel.
|
void |
setMaxSuspensionTravelCm(float maxSuspensionTravelCm)
Alter the initial maximum suspension travel distance for new wheels.
|
void |
setMaxSuspensionTravelCm(int wheelIndex,
float maxSuspensionTravelCm)
Alter the maximum suspension travel distance for the indexed wheel.
|
void |
setRollInfluence(int wheelIndex,
float rollInfluence)
Alter the roll influence of the indexed wheel.
|
void |
setSuspensionCompression(float coefficient)
Alter the initial damping (when the suspension is compressed) for new
wheels.
|
void |
setSuspensionCompression(int wheelIndex,
float coefficient)
Alter the damping (when the suspension is compressed) for the indexed
wheel.
|
void |
setSuspensionDamping(float coefficient)
Alter the initial damping (when the suspension is expanded) for new
wheels.
|
void |
setSuspensionDamping(int wheelIndex,
float coefficient)
Alter the damping (when the suspension is expanded) for the indexed
wheel.
|
void |
setSuspensionStiffness(float coefficient)
Alter the initial suspension stiffness for new wheels.
|
void |
setSuspensionStiffness(int wheelIndex,
float coefficient)
Alter the suspension stiffness of the indexed wheel.
|
void |
steer(float angle)
Alter the steering angle of all front wheels.
|
void |
steer(int wheelIndex,
float angle)
Alter the steering angle of the indexed wheel.
|
int |
upAxisIndex()
Determine the index of this vehicle's up axis.
|
void |
updateWheels()
Used internally.
|
activate, applyCentralForce, applyCentralImpulse, applyForce, applyImpulse, applyTorque, applyTorqueImpulse, clearForces, getAngularDamping, getAngularFactor, getAngularSleepingThreshold, getAngularVelocity, getAngularVelocityDp, getAngularVelocityLocal, getGravity, getGravityDp, getInverseInertiaLocal, getInverseInertiaWorld, getLinearDamping, getLinearFactor, getLinearSleepingThreshold, getLinearVelocity, getLinearVelocityDp, getMass, getMotionState, getSquaredSpeed, isDynamic, isGravityProtected, isKinematic, kineticEnergy, mechanicalEnergy, preRebuild, rebuildRigidBody, setAngularDamping, setAngularFactor, setAngularFactor, setAngularSleepingThreshold, setAngularVelocity, setAngularVelocityDp, setCollisionShape, setContactResponse, setDamping, setEnableSleep, setGravity, setGravityDp, setInverseInertiaLocal, setKinematic, setLinearDamping, setLinearFactor, setLinearSleepingThreshold, setLinearVelocity, setLinearVelocityDp, setMass, setPhysicsLocation, setPhysicsLocationDp, setPhysicsRotation, setPhysicsRotation, setPhysicsRotationDp, setPhysicsRotationDp, setPhysicsScale, setPhysicsTransform, setProtectGravity, setSleepingThresholds, totalAppliedForce, totalAppliedTorqueaddJoint, countJoints, getDeactivationDeadline, isDeactivationEnabled, listJoints, removeJoint, setDeactivationDeadline, setDeactivationEnabledactivate, addCollideWithGroup, addToIgnoreList, attachCollisionShape, boundingBox, clearIgnoreList, collisionFlags, copyPcoProperties, countIgnored, finalizeNative, findInstance, getActivationState, getAnisotropicFriction, getCcdMotionThreshold, getCcdSquareMotionThreshold, getCcdSweptSphereRadius, getCollideWithGroups, getCollisionGroup, getCollisionShape, getCollisionSpace, getContactDamping, getContactProcessingThreshold, getContactStiffness, getDeactivationTime, getFriction, getInternalType, getPhysicsLocation, getPhysicsLocationDp, getPhysicsRotation, getPhysicsRotationDp, getPhysicsRotationMatrix, getPhysicsRotationMatrixDp, getRestitution, getRollingFriction, getScale, getSpinningFriction, getTransform, getTransformDp, getUserObject, hasAnisotropicFriction, ignores, initUserPointer, isActive, isContactResponse, isInWorld, isStatic, listIgnoredPcos, proxyGroup, proxyMask, removeCollideWithGroup, removeFromIgnoreList, setActivationState, setAnisotropicFriction, setCcdMotionThreshold, setCcdSweptSphereRadius, setCollideWithGroups, setCollisionFlags, setCollisionGroup, setContactDamping, setContactProcessingThreshold, setContactStiffness, setDeactivationTime, setFriction, setIgnoreList, setLocationAndBasis, setRestitution, setRollingFriction, setSpinningFriction, setUserIndex, setUserIndex2, setUserIndex3, setUserObject, spaceId, toString, userIndex, userIndex2, userIndex3compareTo, countTrackers, dumpTrackers, equals, freeUnusedObjects, hasAssignedNativeObject, hashCode, nativeId, reassignNativeId, setNativeId, setNativeIdNotTracked, unassignNativeObjectpublic static final java.util.logging.Logger logger3
public PhysicsVehicle(CollisionShape shape)
shape - the desired shape of the chassis (not null, alias created)public PhysicsVehicle(CollisionShape shape, float mass)
shape - the desired shape of the chassis (not null, alias created)mass - the desired mass of the chassis (>0, default=1)public void accelerate(float force)
force - the desired amount of force (may be negative)public void accelerate(int wheelIndex,
float force)
wheelIndex - the index of the wheel to apply the force to (≥0,
<count)force - the desired amount of force (may be negative)public VehicleWheel addWheel(Vector3f connectionPoint, Vector3f direction, Vector3f axle, float suspensionRestLength, float wheelRadius, boolean isFrontWheel)
connectionPoint - the location where the suspension connects to the
chassis (in chassis coordinates, not null, unaffected)direction - the suspension direction (in chassis coordinates, not
null, unaffected, typically down/0,-1,0)axle - the axis direction (in chassis coordinates, not null,
unaffected, typically -1,0,0)suspensionRestLength - the rest length of the suspension (in
physics-space units)wheelRadius - the wheel radius (in physics-space units, >0)isFrontWheel - true→front (steering) wheel,
false→non-front wheelpublic void brake(float impulse)
impulse - the desired impulsepublic void brake(int wheelIndex,
float impulse)
wheelIndex - the index of the wheel to apply the impulse to (≥0,
<count)impulse - the desired impulsepublic float castRay(int wheelIndex)
wheelIndex - the index of the wheel to raycast (≥0, <count)public void createVehicle(PhysicsSpace space)
space - the PhysicsSpace to use, or null for nonepublic int forwardAxisIndex()
public VehicleController getController()
public float getCurrentVehicleSpeedKmHour()
public Vector3f getForwardVector(Vector3f storeResult)
storeResult - storage for the result (modified if not null)public float getFrictionSlip()
public float getMaxSuspensionForce()
public float getMaxSuspensionTravelCm()
public int getNumWheels()
public float getSuspensionCompression()
public float getSuspensionDamping()
public float getSuspensionStiffness()
public VehicleTuning getTuning()
public long getVehicleId()
public VehicleWheel getWheel(int wheelIndex)
wheelIndex - the index of the wheel to access (≥0, <count)public void removeWheel(int wheelIndex)
wheelIndex - the index of the wheel to remove (≥0, <count)public void resetSuspension()
public int rightAxisIndex()
public void setFrictionSlip(float frictionSlip)
setFrictionSlip(int, float).
For better handling, increase the friction.
frictionSlip - the desired coefficient of friction between tire and
ground (0.8→realistic car, 10000→kart racer, default=10.5)public void setFrictionSlip(int wheelIndex,
float frictionSlip)
For better handling, increase the friction.
wheelIndex - the index of the wheel to modify (≥0, <count)frictionSlip - the desired coefficient of friction between tire and
ground (0.8→realistic car, 10000→kart racer, default=10.5)public void setMaxSuspensionForce(float maxSuspensionForce)
setMaxSuspensionForce(int, float).
If the suspension cannot handle the vehicle's weight, increase this limit.
maxSuspensionForce - the desired maximum force per wheel
(default=6000)public void setMaxSuspensionForce(int wheelIndex,
float maxSuspensionForce)
If the suspension cannot handle the vehicle's weight, increase this limit.
wheelIndex - the index of the wheel to modify (≥0, <count)maxSuspensionForce - the desired maximum force per wheel
(default=6000)public void setMaxSuspensionTravelCm(float maxSuspensionTravelCm)
setMaxSuspensionTravelCm(int, float).
Note that the units are centimeters ONLY if the physics-space unit is
exactly one meter.maxSuspensionTravelCm - the desired maximum amount a suspension can
be compressed or expanded, relative to its rest length (in hundredths of
a physics-space unit, default=500)public void setMaxSuspensionTravelCm(int wheelIndex,
float maxSuspensionTravelCm)
wheelIndex - the index of the wheel to modify (≥0, <count)maxSuspensionTravelCm - the desired maximum amount the suspension
can be compressed or expanded, relative to its rest length (in hundredths
of a physics-space unit, default=500)public void setRollInfluence(int wheelIndex,
float rollInfluence)
The roll-influence factor reduces (or magnifies) any torque contributed by the wheel that would tend to cause the vehicle to roll over. This is a bit of a hack, but it's quite effective.
If the friction between the tires and the ground is too high, you may reduce this factor to prevent the vehicle from rolling over. You should also try lowering the vehicle's center of mass.
wheelIndex - the index of the wheel to modify (≥0, <count)rollInfluence - the desired roll-influence factor (0→no roll
torque, 1→realistic behavior, default=1)public void setSuspensionCompression(float coefficient)
setSuspensionCompression(int, float).
Set to k * 2 * FastMath.sqrt(m_suspensionStiffness) where k is the damping ratio:
k = 0.0 undamped and bouncy, k = 1.0 critical damping, k between 0.1 and 0.3 are good values
coefficient - the desired damping coefficient (default=0.83)public void setSuspensionCompression(int wheelIndex,
float coefficient)
Set to k * 2 * FastMath.sqrt(m_suspensionStiffness) where k is the damping ratio:
k = 0.0 undamped and bouncy, k = 1.0 critical damping, k between 0.1 and 0.3 are good values
wheelIndex - the index of the wheel to modify (≥0, <count)coefficient - the desired damping coefficient (default=0.83)public void setSuspensionDamping(float coefficient)
setSuspensionCompression(int, float).
Set to k * 2 * FastMath.sqrt(m_suspensionStiffness) where k is the damping ratio:
k = 0.0 undamped and bouncy, k = 1.0 critical damping, k between 0.1 and 0.3 are good values
coefficient - the desired damping coefficient (default=0.88)public void setSuspensionDamping(int wheelIndex,
float coefficient)
Set to k * 2 * FastMath.sqrt(m_suspensionStiffness) where k is the damping ratio:
k = 0.0 undamped and bouncy, k = 1.0 critical damping, k between 0.1 and 0.3 are good values
wheelIndex - the index of the wheel to modify (≥0, <count)coefficient - the desired damping coefficient (default=0.88)public void setSuspensionStiffness(float coefficient)
setSuspensionStiffness(int, float).coefficient - the desired stiffness coefficient (10→off-road
buggy, 50→sports car, 200→Formula-1 race car, default=5.88)public void setSuspensionStiffness(int wheelIndex,
float coefficient)
wheelIndex - the index of the wheel to modify (≥0, <count)coefficient - the desired stiffness coefficient (10→off-road
buggy, 50→sports car, 200→Formula-1 race car, default=5.88)public void steer(float angle)
angle - the desired angle (in radians, 0=straight, positive=left)public void steer(int wheelIndex,
float angle)
wheelIndex - the index of the wheel to steer (≥0, <count)angle - the desired angle (in radians, 0=straight, positive=left)public int upAxisIndex()
public void updateWheels()
protected void postRebuild()
For use by subclasses.
postRebuild in class PhysicsRigidBody