Package com.jme3.bullet.objects
Class PhysicsVehicle
java.lang.Object
com.jme3.bullet.collision.PhysicsCollisionObject
com.jme3.bullet.objects.PhysicsRigidBody
com.jme3.bullet.objects.PhysicsVehicle
- All Implemented Interfaces:
- Savable
- Direct Known Subclasses:
- VehicleControl
PhysicsVehicleNode - Special PhysicsNode that implements vehicle functions
 From bullet manual:
 For most 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 SummaryFieldsModifier and TypeFieldDescriptionprotected PhysicsSpaceprotected com.bulletphysics.dynamics.vehicle.VehicleRaycasterprotected com.bulletphysics.dynamics.vehicle.VehicleTuningprotected com.bulletphysics.dynamics.vehicle.RaycastVehicleprotected ArrayList<VehicleWheel> Fields inherited from class com.jme3.bullet.objects.PhysicsRigidBodyconstructionInfo, joints, kinematic, localInertia, mass, motionState, rBody, tempMatrix, tempTrans, tempVec, tempVec2Fields inherited from class com.jme3.bullet.collision.PhysicsCollisionObjectCOLLISION_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, collisionGroup, collisionGroupsMask, collisionShape
- 
Constructor SummaryConstructorsModifierConstructorDescriptionprotectedPhysicsVehicle(CollisionShape shape) PhysicsVehicle(CollisionShape shape, float mass) 
- 
Method SummaryModifier and TypeMethodDescriptionvoidaccelerate(float force) Apply the given engine force to all wheels, works continuouslyvoidaccelerate(int wheel, float force) Apply the given engine force, works continuouslyaddWheel(Vector3f connectionPoint, Vector3f direction, Vector3f axle, float suspensionRestLength, float wheelRadius, boolean isFrontWheel) Add a wheel to this vehicleaddWheel(Spatial spat, Vector3f connectionPoint, Vector3f direction, Vector3f axle, float suspensionRestLength, float wheelRadius, boolean isFrontWheel) Add a wheel to this vehiclevoidused internallyvoidbrake(float force) Apply the given brake force to all wheels, works continuouslyvoidbrake(int wheel, float force) Apply the given brake force, works continuouslyvoidcreateVehicle(PhysicsSpace space) Used internally, creates the actual vehicle constraint when vehicle is added to physics spacevoiddestroy()destroys this PhysicsRigidBody and removes it from memoryfloatGet the current speed of the vehicle in km/hgetForwardVector(Vector3f vector) Get the current forward vector of the vehicle in world coordinatesfloatfloatfloatintfloatfloatfloatcom.bulletphysics.dynamics.vehicle.RaycastVehicleused internallygetWheel(int wheel) You can get access to the single wheels via this method.protected voidvoidread(JmeImporter im) De-serialize this body, for example when loading from a J3O file.voidremoveWheel(int wheel) This rebuilds the vehicle as there is no way in bullet to remove a wheel.voidReset the suspensionvoidsetFrictionSlip(float frictionSlip) Use before adding wheels, this is the default used when adding wheels.voidsetFrictionSlip(int wheel, float frictionSlip) The coefficient of friction between the tyre and the ground.voidsetMaxSuspensionForce(float maxSuspensionForce) This value caps the maximum suspension force, raise this above the default 6000 if your suspension cannot handle the weight of your vehicle.voidsetMaxSuspensionForce(int wheel, float maxSuspensionForce) This value caps the maximum suspension force, raise this above the default 6000 if your suspension cannot handle the weight of your vehicle.voidsetMaxSuspensionTravelCm(float maxSuspensionTravelCm) Use before adding wheels, this is the default used when adding wheels.voidsetMaxSuspensionTravelCm(int wheel, float maxSuspensionTravelCm) The maximum distance the suspension can be compressed (centimetres)voidsetRollInfluence(int wheel, float rollInfluence) Reduces the rolling torque applied from the wheels that cause the vehicle to roll over.voidsetSuspensionCompression(float suspensionCompression) Use before adding wheels, this is the default used when adding wheels.voidsetSuspensionCompression(int wheel, float suspensionCompression) The damping coefficient for when the suspension is compressed.voidsetSuspensionDamping(float suspensionDamping) Use before adding wheels, this is the default used when adding wheels.voidsetSuspensionDamping(int wheel, float suspensionDamping) The damping coefficient for when the suspension is expanding.voidsetSuspensionStiffness(float suspensionStiffness) Use before adding wheels, this is the default used when adding wheels.voidsetSuspensionStiffness(int wheel, float suspensionStiffness) The stiffness constant for the suspension.voidsteer(float value) Set the given steering value to all front wheels (0 = forward)voidsteer(int wheel, float value) Set the given steering value to the given wheel (0 = forward)voidused internallyvoidwrite(JmeExporter ex) Serialize this body, for example when saving to a J3O file.Methods inherited from class com.jme3.bullet.objects.PhysicsRigidBodyactivate, addJoint, applyCentralForce, applyForce, applyImpulse, applyTorque, applyTorqueImpulse, clearForces, getAngularDamping, getAngularFactor, getAngularSleepingThreshold, getAngularVelocity, getAngularVelocity, getCcdMotionThreshold, getCcdSquareMotionThreshold, getCcdSweptSphereRadius, getFriction, getGravity, getGravity, getInterpolatedPhysicsLocation, getInterpolatedPhysicsRotation, getJoints, getLinearDamping, getLinearSleepingThreshold, getLinearVelocity, getLinearVelocity, getMass, getMotionState, getObjectId, getPhysicsLocation, getPhysicsLocation, getPhysicsRotation, getPhysicsRotation, getPhysicsRotationMatrix, getPhysicsRotationMatrix, getRestitution, isActive, isContactResponse, isKinematic, preRebuild, rebuildRigidBody, removeJoint, setAngularDamping, setAngularFactor, setAngularSleepingThreshold, setAngularVelocity, setCcdMotionThreshold, setCcdSweptSphereRadius, setCollisionShape, setContactResponse, setDamping, setFriction, setGravity, setKinematic, setLinearDamping, setLinearSleepingThreshold, setLinearVelocity, setMass, setPhysicsLocation, setPhysicsRotation, setPhysicsRotation, setRestitution, setSleepingThresholdsMethods inherited from class com.jme3.bullet.collision.PhysicsCollisionObjectaddCollideWithGroup, getCollideWithGroups, getCollisionGroup, getCollisionShape, getUserObject, removeCollideWithGroup, setCollideWithGroups, setCollisionGroup, setUserObject
- 
Field Details- 
vehicleprotected com.bulletphysics.dynamics.vehicle.RaycastVehicle vehicle
- 
tuningprotected com.bulletphysics.dynamics.vehicle.VehicleTuning tuning
- 
rayCasterprotected com.bulletphysics.dynamics.vehicle.VehicleRaycaster rayCaster
- 
wheels
- 
physicsSpace
 
- 
- 
Constructor Details- 
PhysicsVehicleprotected PhysicsVehicle()
- 
PhysicsVehicle
- 
PhysicsVehicle
 
- 
- 
Method Details- 
updateWheelspublic void updateWheels()used internally
- 
applyWheelTransformspublic void applyWheelTransforms()used internally
- 
postRebuildprotected void postRebuild()- Overrides:
- postRebuildin class- PhysicsRigidBody
 
- 
createVehicleUsed internally, creates the actual vehicle constraint when vehicle is added to physics space- Parameters:
- space- the PhysicsSpace to use (alias created) or null for none
 
- 
addWheelpublic VehicleWheel addWheel(Vector3f connectionPoint, Vector3f direction, Vector3f axle, float suspensionRestLength, float wheelRadius, boolean isFrontWheel) Add a wheel to this vehicle- Parameters:
- connectionPoint- The starting point of the ray, where the suspension connects to the chassis (chassis space)
- direction- the direction of the wheel (should be -Y / 0,-1,0 for a normal car)
- axle- The axis of the wheel, pointing right in vehicle direction (should be -X / -1,0,0 for a normal car)
- suspensionRestLength- The current length of the suspension (metres)
- wheelRadius- the wheel radius
- isFrontWheel- sets if this wheel is a front wheel (steering)
- Returns:
- the PhysicsVehicleWheel object to get/set infos on the wheel
 
- 
addWheelpublic VehicleWheel addWheel(Spatial spat, Vector3f connectionPoint, Vector3f direction, Vector3f axle, float suspensionRestLength, float wheelRadius, boolean isFrontWheel) Add a wheel to this vehicle- Parameters:
- spat- the wheel Geometry
- connectionPoint- The starting point of the ray, where the suspension connects to the chassis (chassis space)
- direction- the direction of the wheel (should be -Y / 0,-1,0 for a normal car)
- axle- The axis of the wheel, pointing right in vehicle direction (should be -X / -1,0,0 for a normal car)
- suspensionRestLength- The current length of the suspension (metres)
- wheelRadius- the wheel radius
- isFrontWheel- sets if this wheel is a front wheel (steering)
- Returns:
- the PhysicsVehicleWheel object to get/set infos on the wheel
 
- 
removeWheelpublic void removeWheel(int wheel) This rebuilds the vehicle as there is no way in bullet to remove a wheel.- Parameters:
- wheel- the index of the wheel to remove (≥0, <count)
 
- 
getWheelYou can get access to the single wheels via this method.- Parameters:
- wheel- the wheel index
- Returns:
- the WheelInfo of the selected wheel
 
- 
getNumWheelspublic int getNumWheels()
- 
getFrictionSlippublic float getFrictionSlip()- Returns:
- the frictionSlip
 
- 
setFrictionSlippublic void setFrictionSlip(float frictionSlip) Use before adding wheels, this is the default used when adding wheels. After adding the wheel, use direct wheel access.
 The coefficient of friction between the tyre and the ground. Should be about 0.8 for realistic cars, but can be increased for better handling. Set large (10000.0) for kart racers.- Parameters:
- frictionSlip- the frictionSlip to set
 
- 
setFrictionSlippublic void setFrictionSlip(int wheel, float frictionSlip) The coefficient of friction between the tyre and the ground. Should be about 0.8 for realistic cars, but can be increased for better handling. Set large (10000.0) for kart racers.- Parameters:
- wheel- the index of the wheel to modify (≥0, <count)
- frictionSlip- the desired coefficient of friction between tyre and ground (0.8→realistic car, 10000→kart racer, default=10.5)
 
- 
setRollInfluencepublic void setRollInfluence(int wheel, float rollInfluence) Reduces the rolling torque applied from the wheels that cause the vehicle to roll over. This is a bit of a hack, but it's quite effective. 0.0 = no roll, 1.0 = physical behaviour. If m_frictionSlip is too high, you'll need to reduce this to stop the vehicle rolling over. You should also try lowering the vehicle's centre of mass- Parameters:
- wheel- the index of the wheel to modify (≥0, <count)
- rollInfluence- the desired roll-influence factor (0→no roll torque, 1→realistic behavior, default=1)
 
- 
getMaxSuspensionTravelCmpublic float getMaxSuspensionTravelCm()- Returns:
- the maxSuspensionTravelCm
 
- 
setMaxSuspensionTravelCmpublic void setMaxSuspensionTravelCm(float maxSuspensionTravelCm) Use before adding wheels, this is the default used when adding wheels. After adding the wheel, use direct wheel access.
 The maximum distance the suspension can be compressed (centimetres)- Parameters:
- maxSuspensionTravelCm- the maxSuspensionTravelCm to set
 
- 
setMaxSuspensionTravelCmpublic void setMaxSuspensionTravelCm(int wheel, float maxSuspensionTravelCm) The maximum distance the suspension can be compressed (centimetres)- Parameters:
- wheel- the index of the wheel to modify (≥0, <count)
- 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)
 
- 
getMaxSuspensionForcepublic float getMaxSuspensionForce()
- 
setMaxSuspensionForcepublic void setMaxSuspensionForce(float maxSuspensionForce) This value caps the maximum suspension force, raise this above the default 6000 if your suspension cannot handle the weight of your vehicle.- Parameters:
- maxSuspensionForce- the desired maximum force per wheel (default=6000)
 
- 
setMaxSuspensionForcepublic void setMaxSuspensionForce(int wheel, float maxSuspensionForce) This value caps the maximum suspension force, raise this above the default 6000 if your suspension cannot handle the weight of your vehicle.- Parameters:
- wheel- the index of the wheel to modify (≥0, <count)
- maxSuspensionForce- the desired maximum force per wheel (default=6000)
 
- 
getSuspensionCompressionpublic float getSuspensionCompression()- Returns:
- the suspensionCompression
 
- 
setSuspensionCompressionpublic void setSuspensionCompression(float suspensionCompression) Use before adding wheels, this is the default used when adding wheels. After adding the wheel, use direct wheel access.
 The damping coefficient for when the suspension is compressed. Set to k * 2.0 * FastMath.sqrt(m_suspensionStiffness) so k is proportional to critical damping.
 k = 0.0 undamped/bouncy, k = 1.0 critical damping
 0.1 to 0.3 are good values- Parameters:
- suspensionCompression- the suspensionCompression to set
 
- 
setSuspensionCompressionpublic void setSuspensionCompression(int wheel, float suspensionCompression) The damping coefficient for when the suspension is compressed. Set to k * 2.0 * FastMath.sqrt(m_suspensionStiffness) so k is proportional to critical damping.
 k = 0.0 undamped/bouncy, k = 1.0 critical damping
 0.1 to 0.3 are good values- Parameters:
- wheel- the index of the wheel to modify (≥0, <count)
- suspensionCompression- the desired damping coefficient (default=4.4)
 
- 
getSuspensionDampingpublic float getSuspensionDamping()- Returns:
- the suspensionDamping
 
- 
setSuspensionDampingpublic void setSuspensionDamping(float suspensionDamping) Use before adding wheels, this is the default used when adding wheels. After adding the wheel, use direct wheel access.
 The damping coefficient for when the suspension is expanding. See the comments for setSuspensionCompression for how to set k.- Parameters:
- suspensionDamping- the suspensionDamping to set
 
- 
setSuspensionDampingpublic void setSuspensionDamping(int wheel, float suspensionDamping) The damping coefficient for when the suspension is expanding. See the comments for setSuspensionCompression for how to set k.- Parameters:
- wheel- the index of the wheel to modify (≥0, <count)
- suspensionDamping- the desired damping coefficient (default=2.3)
 
- 
getSuspensionStiffnesspublic float getSuspensionStiffness()- Returns:
- the suspensionStiffness
 
- 
setSuspensionStiffnesspublic void setSuspensionStiffness(float suspensionStiffness) Use before adding wheels, this is the default used when adding wheels. After adding the wheel, use direct wheel access.
 The stiffness constant for the suspension. 10.0 - Off-road buggy, 50.0 - Sports car, 200.0 - F1 Car- Parameters:
- suspensionStiffness- the desired stiffness coefficient (10→off-road buggy, 50→sports car, 200→Formula-1 race car, default=5.88)
 
- 
setSuspensionStiffnesspublic void setSuspensionStiffness(int wheel, float suspensionStiffness) The stiffness constant for the suspension. 10.0 - Off-road buggy, 50.0 - Sports car, 200.0 - F1 Car- Parameters:
- wheel- the index of the wheel to modify (≥0, <count)
- suspensionStiffness- the desired stiffness coefficient (10→off-road buggy, 50→sports car, 200→Formula-1 race car, default=5.88)
 
- 
resetSuspensionpublic void resetSuspension()Reset the suspension
- 
acceleratepublic void accelerate(float force) Apply the given engine force to all wheels, works continuously- Parameters:
- force- the force
 
- 
acceleratepublic void accelerate(int wheel, float force) Apply the given engine force, works continuously- Parameters:
- wheel- the wheel to apply the force on
- force- the force
 
- 
steerpublic void steer(float value) Set the given steering value to all front wheels (0 = forward)- Parameters:
- value- the steering angle of the front wheels (Pi = 360deg)
 
- 
steerpublic void steer(int wheel, float value) Set the given steering value to the given wheel (0 = forward)- Parameters:
- wheel- the wheel to set the steering on
- value- the steering angle of the front wheels (Pi = 360deg)
 
- 
brakepublic void brake(float force) Apply the given brake force to all wheels, works continuously- Parameters:
- force- the force
 
- 
brakepublic void brake(int wheel, float force) Apply the given brake force, works continuously- Parameters:
- wheel- the wheel to apply the force on
- force- the force
 
- 
getCurrentVehicleSpeedKmHourpublic float getCurrentVehicleSpeedKmHour()Get the current speed of the vehicle in km/h- Returns:
- the speed
 
- 
getForwardVectorGet the current forward vector of the vehicle in world coordinates- Parameters:
- vector- The object to write the forward vector values to. Passing null will cause a new- Vector3fto be created.
- Returns:
- The forward vector
 
- 
getVehicleIdpublic com.bulletphysics.dynamics.vehicle.RaycastVehicle getVehicleId()used internally- Returns:
- the pre-existing instance
 
- 
destroypublic void destroy()Description copied from class:PhysicsRigidBodydestroys this PhysicsRigidBody and removes it from memory- Overrides:
- destroyin class- PhysicsRigidBody
 
- 
readDescription copied from class:PhysicsRigidBodyDe-serialize this body, for example when loading from a J3O file.- Specified by:
- readin interface- Savable
- Overrides:
- readin class- PhysicsRigidBody
- Parameters:
- im- importer (not null)
- Throws:
- IOException- from importer
 
- 
writeDescription copied from class:PhysicsRigidBodySerialize this body, for example when saving to a J3O file.- Specified by:
- writein interface- Savable
- Overrides:
- writein class- PhysicsRigidBody
- Parameters:
- ex- exporter (not null)
- Throws:
- IOException- from exporter
 
 
-