Class PhysicsVehicle
- All Implemented Interfaces:
Comparable<NativePhysicsObject>
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.
-
Field Summary
FieldsFields inherited from class com.jme3.bullet.objects.PhysicsRigidBody
logger2, massFields inherited from class com.jme3.bullet.objects.PhysicsBody
massForStaticFields inherited from class com.jme3.bullet.collision.PhysicsCollisionObject
COLLISION_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, loggerFields inherited from class com.jme3.bullet.NativePhysicsObject
loggerN -
Constructor Summary
ConstructorsConstructorDescriptionPhysicsVehicle(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. -
Method Summary
Modifier and TypeMethodDescriptionvoidaccelerate(float force) Apply the specified engine force to each wheel.voidaccelerate(int wheelIndex, float force) Apply the specified engine force to the indexed wheel.addWheel(Vector3f connectionPoint, Vector3f direction, Vector3f axle, float suspensionRestLength, float wheelRadius, boolean isFrontWheel) Add a wheel to this vehicle.voidbrake(float impulse) Apply the specified brake impulse to all wheels.voidbrake(int wheelIndex, float impulse) Apply the specified brake impulse to the indexed wheel.floatcastRay(int wheelIndex) Compute depth for the indexed wheel by raycasting.voidcreateVehicle(PhysicsSpace space) Used internally, creates the controller when the vehicle is added to a PhysicsSpace.intDetermine the index of this vehicle's forward axis.Access this vehicle's controller.floatDetermine this vehicle's forward velocity as of the previous simulation step.getForwardVector(Vector3f storeResult) Determine this vehicle's forward direction.floatDetermine the initial friction for new wheels.floatDetermine the initial maximum suspension force for new wheels.floatDetermine the initial maximum suspension travel distance for new wheels.intCount the number of wheels on this vehicle.floatDetermine the initial damping (when the suspension is compressed) for new wheels.floatDetermine the initial damping (when the suspension is expanded) for new wheels.floatDetermine the initial suspension stiffness for new wheels.Access the tuning parameters applied when a wheel is created.longUsed internally.getWheel(int wheelIndex) Access the indexed wheel of this vehicle.protected voidInvoked during a rebuild after the native object is created.voidremoveWheel(int wheelIndex) Remove a wheel.voidReset this vehicle's suspension.intDetermine the index of this vehicle's right-side axis.voidsetFrictionSlip(float frictionSlip) Alter the initial friction for new wheels.voidsetFrictionSlip(int wheelIndex, float frictionSlip) Alter the friction of the indexed wheel.voidsetMaxSuspensionForce(float maxSuspensionForce) Alter the initial maximum suspension force for new wheels.voidsetMaxSuspensionForce(int wheelIndex, float maxSuspensionForce) Alter the maximum suspension force for the specified wheel.voidsetMaxSuspensionTravelCm(float maxSuspensionTravelCm) Alter the initial maximum suspension travel distance for new wheels.voidsetMaxSuspensionTravelCm(int wheelIndex, float maxSuspensionTravelCm) Alter the maximum suspension travel distance for the indexed wheel.voidsetRollInfluence(int wheelIndex, float rollInfluence) Alter the roll influence of the indexed wheel.voidsetSuspensionCompression(float coefficient) Alter the initial damping (when the suspension is compressed) for new wheels.voidsetSuspensionCompression(int wheelIndex, float coefficient) Alter the damping (when the suspension is compressed) for the indexed wheel.voidsetSuspensionDamping(float coefficient) Alter the initial damping (when the suspension is expanded) for new wheels.voidsetSuspensionDamping(int wheelIndex, float coefficient) Alter the damping (when the suspension is expanded) for the indexed wheel.voidsetSuspensionStiffness(float coefficient) Alter the initial suspension stiffness for new wheels.voidsetSuspensionStiffness(int wheelIndex, float coefficient) Alter the suspension stiffness of the indexed wheel.voidsteer(float angle) Alter the steering angle of all front wheels.voidsteer(int wheelIndex, float angle) Alter the steering angle of the indexed wheel.intDetermine the index of this vehicle's up axis.voidUpdate the wheel transforms for visualization.Methods inherited from class com.jme3.bullet.objects.PhysicsRigidBody
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, totalAppliedTorqueMethods inherited from class com.jme3.bullet.objects.PhysicsBody
addJoint, countJoints, getDeactivationDeadline, isDeactivationEnabled, listJoints, removeJoint, setDeactivationDeadline, setDeactivationEnabledMethods inherited from class com.jme3.bullet.collision.PhysicsCollisionObject
activate, 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, userIndex3Methods inherited from class com.jme3.bullet.NativePhysicsObject
compareTo, countTrackers, dumpTrackers, equals, freeUnusedObjects, hasAssignedNativeObject, hashCode, nativeId, reassignNativeId, setNativeId, setNativeIdNotTracked, unassignNativeObject
-
Field Details
-
logger3
message logger for this class
-
-
Constructor Details
-
PhysicsVehicle
Instantiate a responsive vehicle with the specified CollisionShape and mass=1.- Parameters:
shape- the desired shape of the chassis (not null, alias created)
-
PhysicsVehicle
Instantiate a responsive vehicle with the specified CollisionShape and mass.- Parameters:
shape- the desired shape of the chassis (not null, alias created)mass- the desired mass of the chassis (>0, default=1)
-
-
Method Details
-
accelerate
public void accelerate(float force) Apply the specified engine force to each wheel. Works continuously. The vehicle must be added to a PhysicsSpace.- Parameters:
force- the desired amount of force (may be negative)
-
accelerate
public void accelerate(int wheelIndex, float force) Apply the specified engine force to the indexed wheel. Works continuously. The vehicle must be added to a PhysicsSpace.- Parameters:
wheelIndex- the index of the wheel to apply the force to (≥0, <count)force- the desired amount of force (may be negative)
-
addWheel
public VehicleWheel addWheel(Vector3f connectionPoint, Vector3f direction, Vector3f axle, float suspensionRestLength, float wheelRadius, boolean isFrontWheel) Add a wheel to this vehicle.- Parameters:
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 wheel- Returns:
- a new VehicleWheel for access (not null)
-
brake
public void brake(float impulse) Apply the specified brake impulse to all wheels. Works continuously. The vehicle must be added to a PhysicsSpace.- Parameters:
impulse- the desired impulse
-
brake
public void brake(int wheelIndex, float impulse) Apply the specified brake impulse to the indexed wheel. Works continuously. The vehicle must be added to a PhysicsSpace.- Parameters:
wheelIndex- the index of the wheel to apply the impulse to (≥0, <count)impulse- the desired impulse
-
castRay
public float castRay(int wheelIndex) Compute depth for the indexed wheel by raycasting. The vehicle must be added to a PhysicsSpace.- Parameters:
wheelIndex- the index of the wheel to raycast (≥0, <count)- Returns:
- the depth value, or -1 if the raycast finds no result
-
createVehicle
Used internally, creates the controller when the vehicle is added to a PhysicsSpace.- Parameters:
space- the PhysicsSpace to use, or null for none
-
forwardAxisIndex
public int forwardAxisIndex()Determine the index of this vehicle's forward axis. The vehicle must be added to a PhysicsSpace.- Returns:
- the index of the local axis: 0→X, 1→Y, 2→Z, -1→custom axes
-
getController
Access this vehicle's controller.- Returns:
- the pre-existing instance, or null if never added to a PhysicsSpace
-
getCurrentVehicleSpeedKmHour
public float getCurrentVehicleSpeedKmHour()Determine this vehicle's forward velocity as of the previous simulation step. The vehicle must be added to a PhysicsSpace. Note that the units are kilometers per hour ONLY if the physics-space unit is exactly one meter.- Returns:
- the forward component of the linear velocity (in physics-space units per 3.6 seconds, may be negative)
-
getForwardVector
Determine this vehicle's forward direction. The vehicle must be added to a PhysicsSpace.- Parameters:
storeResult- storage for the result (modified if not null)- Returns:
- a direction vector (in physics-space coordinates, either storeResult or a new vector, not null)
-
getFrictionSlip
public float getFrictionSlip()Determine the initial friction for new wheels.- Returns:
- the coefficient of friction between tire and ground (0.8→realistic car, 10000→kart racer)
-
getMaxSuspensionForce
public float getMaxSuspensionForce()Determine the initial maximum suspension force for new wheels.- Returns:
- the maximum force per wheel
-
getMaxSuspensionTravelCm
public float getMaxSuspensionTravelCm()Determine the initial maximum suspension travel distance for new wheels. Note that the units are centimeters ONLY if the physics-space unit is exactly one meter.- Returns:
- the maximum amount a suspension can be compressed or expanded, relative to its rest length (in hundredths of a physics-space unit)
-
getNumWheels
public int getNumWheels()Count the number of wheels on this vehicle.- Returns:
- count (≥0)
-
getSuspensionCompression
public float getSuspensionCompression()Determine the initial damping (when the suspension is compressed) for new wheels.- Returns:
- the damping coefficient
-
getSuspensionDamping
public float getSuspensionDamping()Determine the initial damping (when the suspension is expanded) for new wheels.- Returns:
- the damping coefficient
-
getSuspensionStiffness
public float getSuspensionStiffness()Determine the initial suspension stiffness for new wheels.- Returns:
- the stiffness constant (10→off-road buggy, 50→sports car, 200→Formula-1 race car)
-
getTuning
Access the tuning parameters applied when a wheel is created.- Returns:
- the pre-existing instance (not null)
-
getVehicleId
public long getVehicleId()Used internally.- Returns:
- the unique identifier (not zero)
-
getWheel
Access the indexed wheel of this vehicle.- Parameters:
wheelIndex- the index of the wheel to access (≥0, <count)- Returns:
- the pre-existing instance
-
removeWheel
public void removeWheel(int wheelIndex) Remove a wheel. TODO test this---with joints!- Parameters:
wheelIndex- the index of the wheel to remove (≥0, <count)
-
resetSuspension
public void resetSuspension()Reset this vehicle's suspension. The vehicle must be added to a PhysicsSpace. -
rightAxisIndex
public int rightAxisIndex()Determine the index of this vehicle's right-side axis. The vehicle must be added to a PhysicsSpace.- Returns:
- the index of the local axis: 0→X, 1→Y, 2→Z, -1→custom axes
-
setFrictionSlip
public void setFrictionSlip(float frictionSlip) Alter the initial friction for new wheels. Effective only before adding wheels. After adding a wheel, usesetFrictionSlip(int, float).For better handling, increase the friction.
- Parameters:
frictionSlip- the desired coefficient of friction between tire and ground (0.8→realistic car, 10000→kart racer, default=10.5)
-
setFrictionSlip
public void setFrictionSlip(int wheelIndex, float frictionSlip) Alter the friction of the indexed wheel.For better handling, increase the friction.
- Parameters:
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)
-
setMaxSuspensionForce
public void setMaxSuspensionForce(float maxSuspensionForce) Alter the initial maximum suspension force for new wheels. Effective only before adding wheels. After adding a wheel, usesetMaxSuspensionForce(int, float).If the suspension cannot handle the vehicle's weight, increase this limit.
- Parameters:
maxSuspensionForce- the desired maximum force per wheel (default=6000)
-
setMaxSuspensionForce
public void setMaxSuspensionForce(int wheelIndex, float maxSuspensionForce) Alter the maximum suspension force for the specified wheel.If the suspension cannot handle the vehicle's weight, increase this limit.
- Parameters:
wheelIndex- the index of the wheel to modify (≥0, <count)maxSuspensionForce- the desired maximum force per wheel (default=6000)
-
setMaxSuspensionTravelCm
public void setMaxSuspensionTravelCm(float maxSuspensionTravelCm) Alter the initial maximum suspension travel distance for new wheels. Effective only before adding wheels. After adding a wheel, usesetMaxSuspensionTravelCm(int, float). Note that the units are centimeters ONLY if the physics-space unit is exactly one meter.- Parameters:
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)
-
setMaxSuspensionTravelCm
public void setMaxSuspensionTravelCm(int wheelIndex, float maxSuspensionTravelCm) Alter the maximum suspension travel distance for the indexed wheel. Note that the units are centimeters ONLY if the physics-space unit is exactly one meter.- Parameters:
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)
-
setRollInfluence
public void setRollInfluence(int wheelIndex, float rollInfluence) Alter the roll influence of the indexed wheel.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.
- Parameters:
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)
-
setSuspensionCompression
public void setSuspensionCompression(float coefficient) Alter the initial damping (when the suspension is compressed) for new wheels. Effective only before adding wheels. After adding a wheel, usesetSuspensionCompression(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
- Parameters:
coefficient- the desired damping coefficient (default=0.83)
-
setSuspensionCompression
public void setSuspensionCompression(int wheelIndex, float coefficient) Alter the damping (when the suspension is compressed) for the indexed wheel.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
- Parameters:
wheelIndex- the index of the wheel to modify (≥0, <count)coefficient- the desired damping coefficient (default=0.83)
-
setSuspensionDamping
public void setSuspensionDamping(float coefficient) Alter the initial damping (when the suspension is expanded) for new wheels. Effective only before adding wheels. After adding a wheel, usesetSuspensionCompression(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
- Parameters:
coefficient- the desired damping coefficient (default=0.88)
-
setSuspensionDamping
public void setSuspensionDamping(int wheelIndex, float coefficient) Alter the damping (when the suspension is expanded) for the indexed wheel.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
- Parameters:
wheelIndex- the index of the wheel to modify (≥0, <count)coefficient- the desired damping coefficient (default=0.88)
-
setSuspensionStiffness
public void setSuspensionStiffness(float coefficient) Alter the initial suspension stiffness for new wheels. Effective only before adding wheels. After adding a wheel, usesetSuspensionStiffness(int, float).- Parameters:
coefficient- the desired stiffness coefficient (10→off-road buggy, 50→sports car, 200→Formula-1 race car, default=5.88)
-
setSuspensionStiffness
public void setSuspensionStiffness(int wheelIndex, float coefficient) Alter the suspension stiffness of the indexed wheel.- Parameters:
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)
-
steer
public void steer(float angle) Alter the steering angle of all front wheels. The vehicle must be added to a PhysicsSpace.- Parameters:
angle- the desired angle (in radians, 0=straight, positive=left)
-
steer
public void steer(int wheelIndex, float angle) Alter the steering angle of the indexed wheel. The vehicle must be added to a PhysicsSpace.- Parameters:
wheelIndex- the index of the wheel to steer (≥0, <count)angle- the desired angle (in radians, 0=straight, positive=left)
-
upAxisIndex
public int upAxisIndex()Determine the index of this vehicle's up axis. The vehicle must be added to a PhysicsSpace.- Returns:
- the index of the local axis: 0→X, 1→Y, 2→Z, -1→custom axes
-
updateWheels
public void updateWheels()Update the wheel transforms for visualization. (In Minie this gets invoked when the VehicleControl is updated.) -
postRebuild
protected void postRebuild()Invoked during a rebuild after the native object is created.For use by subclasses.
- Overrides:
postRebuildin classPhysicsRigidBody
-