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 Summary
Modifier and TypeFieldDescriptionprotected PhysicsSpace
protected com.bulletphysics.dynamics.vehicle.VehicleRaycaster
protected com.bulletphysics.dynamics.vehicle.VehicleTuning
protected com.bulletphysics.dynamics.vehicle.RaycastVehicle
protected ArrayList<VehicleWheel>
Fields inherited from class com.jme3.bullet.objects.PhysicsRigidBody
constructionInfo, joints, kinematic, localInertia, mass, motionState, rBody, tempMatrix, tempTrans, tempVec, tempVec2
Fields 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, collisionGroup, collisionGroupsMask, collisionShape
-
Constructor Summary
ModifierConstructorDescriptionprotected
PhysicsVehicle
(CollisionShape shape) PhysicsVehicle
(CollisionShape shape, float mass) -
Method Summary
Modifier and TypeMethodDescriptionvoid
accelerate
(float force) Apply the given engine force to all wheels, works continuouslyvoid
accelerate
(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 vehiclevoid
used internallyvoid
brake
(float force) Apply the given brake force to all wheels, works continuouslyvoid
brake
(int wheel, float force) Apply the given brake force, works continuouslyvoid
createVehicle
(PhysicsSpace space) Used internally, creates the actual vehicle constraint when vehicle is added to physics spacevoid
destroy()
destroys this PhysicsRigidBody and removes it from memoryfloat
Get the current speed of the vehicle in km/hgetForwardVector
(Vector3f vector) Get the current forward vector of the vehicle in world coordinatesfloat
float
float
int
float
float
float
com.bulletphysics.dynamics.vehicle.RaycastVehicle
used internallygetWheel
(int wheel) You can get access to the single wheels via this method.protected void
void
read
(JmeImporter im) De-serialize this body, for example when loading from a J3O file.void
removeWheel
(int wheel) This rebuilds the vehicle as there is no way in bullet to remove a wheel.void
Reset the suspensionvoid
setFrictionSlip
(float frictionSlip) Use before adding wheels, this is the default used when adding wheels.void
setFrictionSlip
(int wheel, float frictionSlip) The coefficient of friction between the tyre and the ground.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.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.void
setMaxSuspensionTravelCm
(float maxSuspensionTravelCm) Use before adding wheels, this is the default used when adding wheels.void
setMaxSuspensionTravelCm
(int wheel, float maxSuspensionTravelCm) The maximum distance the suspension can be compressed (centimetres)void
setRollInfluence
(int wheel, float rollInfluence) Reduces the rolling torque applied from the wheels that cause the vehicle to roll over.void
setSuspensionCompression
(float suspensionCompression) Use before adding wheels, this is the default used when adding wheels.void
setSuspensionCompression
(int wheel, float suspensionCompression) The damping coefficient for when the suspension is compressed.void
setSuspensionDamping
(float suspensionDamping) Use before adding wheels, this is the default used when adding wheels.void
setSuspensionDamping
(int wheel, float suspensionDamping) The damping coefficient for when the suspension is expanding.void
setSuspensionStiffness
(float suspensionStiffness) Use before adding wheels, this is the default used when adding wheels.void
setSuspensionStiffness
(int wheel, float suspensionStiffness) The stiffness constant for the suspension.void
steer
(float value) Set the given steering value to all front wheels (0 = forward)void
steer
(int wheel, float value) Set the given steering value to the given wheel (0 = forward)void
used internallyvoid
write
(JmeExporter ex) Serialize this body, for example when saving to a J3O file.Methods inherited from class com.jme3.bullet.objects.PhysicsRigidBody
activate, 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, setSleepingThresholds
Methods inherited from class com.jme3.bullet.collision.PhysicsCollisionObject
addCollideWithGroup, getCollideWithGroups, getCollisionGroup, getCollisionShape, getUserObject, removeCollideWithGroup, setCollideWithGroups, setCollisionGroup, setUserObject
-
Field Details
-
vehicle
protected com.bulletphysics.dynamics.vehicle.RaycastVehicle vehicle -
tuning
protected com.bulletphysics.dynamics.vehicle.VehicleTuning tuning -
rayCaster
protected com.bulletphysics.dynamics.vehicle.VehicleRaycaster rayCaster -
wheels
-
physicsSpace
-
-
Constructor Details
-
PhysicsVehicle
protected PhysicsVehicle() -
PhysicsVehicle
-
PhysicsVehicle
-
-
Method Details
-
updateWheels
public void updateWheels()used internally -
applyWheelTransforms
public void applyWheelTransforms()used internally -
postRebuild
protected void postRebuild()- Overrides:
postRebuild
in classPhysicsRigidBody
-
createVehicle
Used 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
-
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 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 radiusisFrontWheel
- sets if this wheel is a front wheel (steering)- Returns:
- the PhysicsVehicleWheel object to get/set infos on the wheel
-
addWheel
public 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 GeometryconnectionPoint
- 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 radiusisFrontWheel
- sets if this wheel is a front wheel (steering)- Returns:
- the PhysicsVehicleWheel object to get/set infos on the wheel
-
removeWheel
public 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)
-
getWheel
You can get access to the single wheels via this method.- Parameters:
wheel
- the wheel index- Returns:
- the WheelInfo of the selected wheel
-
getNumWheels
public int getNumWheels() -
getFrictionSlip
public float getFrictionSlip()- Returns:
- the frictionSlip
-
setFrictionSlip
public 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
-
setFrictionSlip
public 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)
-
setRollInfluence
public 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)
-
getMaxSuspensionTravelCm
public float getMaxSuspensionTravelCm()- Returns:
- the maxSuspensionTravelCm
-
setMaxSuspensionTravelCm
public 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
-
setMaxSuspensionTravelCm
public 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)
-
getMaxSuspensionForce
public float getMaxSuspensionForce() -
setMaxSuspensionForce
public 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)
-
setMaxSuspensionForce
public 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)
-
getSuspensionCompression
public float getSuspensionCompression()- Returns:
- the suspensionCompression
-
setSuspensionCompression
public 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
-
setSuspensionCompression
public 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)
-
getSuspensionDamping
public float getSuspensionDamping()- Returns:
- the suspensionDamping
-
setSuspensionDamping
public 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
-
setSuspensionDamping
public 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)
-
getSuspensionStiffness
public float getSuspensionStiffness()- Returns:
- the suspensionStiffness
-
setSuspensionStiffness
public 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)
-
setSuspensionStiffness
public 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)
-
resetSuspension
public void resetSuspension()Reset the suspension -
accelerate
public void accelerate(float force) Apply the given engine force to all wheels, works continuously- Parameters:
force
- the force
-
accelerate
public void accelerate(int wheel, float force) Apply the given engine force, works continuously- Parameters:
wheel
- the wheel to apply the force onforce
- the force
-
steer
public 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)
-
steer
public 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 onvalue
- the steering angle of the front wheels (Pi = 360deg)
-
brake
public void brake(float force) Apply the given brake force to all wheels, works continuously- Parameters:
force
- the force
-
brake
public void brake(int wheel, float force) Apply the given brake force, works continuously- Parameters:
wheel
- the wheel to apply the force onforce
- the force
-
getCurrentVehicleSpeedKmHour
public float getCurrentVehicleSpeedKmHour()Get the current speed of the vehicle in km/h- Returns:
- the speed
-
getForwardVector
Get 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 newVector3f
to be created.- Returns:
- The forward vector
-
getVehicleId
public com.bulletphysics.dynamics.vehicle.RaycastVehicle getVehicleId()used internally- Returns:
- the pre-existing instance
-
destroy
public void destroy()Description copied from class:PhysicsRigidBody
destroys this PhysicsRigidBody and removes it from memory- Overrides:
destroy
in classPhysicsRigidBody
-
read
Description copied from class:PhysicsRigidBody
De-serialize this body, for example when loading from a J3O file.- Specified by:
read
in interfaceSavable
- Overrides:
read
in classPhysicsRigidBody
- Parameters:
im
- importer (not null)- Throws:
IOException
- from importer
-
write
Description copied from class:PhysicsRigidBody
Serialize this body, for example when saving to a J3O file.- Specified by:
write
in interfaceSavable
- Overrides:
write
in classPhysicsRigidBody
- Parameters:
ex
- exporter (not null)- Throws:
IOException
- from exporter
-