public class PhysicsVehicle extends PhysicsRigidBody
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 rigidbody, 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 |
|---|---|
protected PhysicsSpace |
physicsSpace |
protected long |
rayCasterId |
protected VehicleTuning |
tuning |
protected long |
vehicleId |
protected java.util.ArrayList<VehicleWheel> |
wheels |
joints, kinematic, mass, motionStateCOLLISION_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, objectId| Constructor and Description |
|---|
PhysicsVehicle() |
PhysicsVehicle(CollisionShape shape) |
PhysicsVehicle(CollisionShape shape,
float mass) |
| Modifier and Type | Method and Description |
|---|---|
void |
accelerate(float force)
Apply the given engine force to all wheels, works continuously
|
void |
accelerate(int wheel,
float force)
Apply the given engine force, works continuously
|
VehicleWheel |
addWheel(com.jme3.scene.Spatial spat,
com.jme3.math.Vector3f connectionPoint,
com.jme3.math.Vector3f direction,
com.jme3.math.Vector3f axle,
float suspensionRestLength,
float wheelRadius,
boolean isFrontWheel)
Add a wheel to this vehicle
|
VehicleWheel |
addWheel(com.jme3.math.Vector3f connectionPoint,
com.jme3.math.Vector3f direction,
com.jme3.math.Vector3f axle,
float suspensionRestLength,
float wheelRadius,
boolean isFrontWheel)
Add a wheel to this vehicle
|
void |
applyWheelTransforms()
used internally
|
void |
brake(float force)
Apply the given brake force to all wheels, works continuously
|
void |
brake(int wheel,
float force)
Apply the given brake force, works continuously
|
void |
createVehicle(PhysicsSpace space)
Used internally, creates the actual vehicle constraint when vehicle is added to phyicsspace
|
protected void |
finalize() |
float |
getCurrentVehicleSpeedKmHour()
Get the current speed of the vehicle in km/h
|
com.jme3.math.Vector3f |
getForwardVector(com.jme3.math.Vector3f vector)
Get the current forward vector of the vehicle in world coordinates
|
float |
getFrictionSlip() |
float |
getMaxSuspensionForce() |
float |
getMaxSuspensionTravelCm() |
int |
getNumWheels() |
float |
getSuspensionCompression() |
float |
getSuspensionDamping() |
float |
getSuspensionStiffness() |
long |
getVehicleId()
used internally
|
VehicleWheel |
getWheel(int wheel)
You can get access to the single wheels via this method.
|
protected void |
postRebuild() |
void |
read(com.jme3.export.JmeImporter im) |
void |
removeWheel(int wheel)
This rebuilds the vehicle as there is no way in bullet to remove a wheel.
|
void |
resetSuspension()
Reset the suspension
|
void |
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 vaue caps the maximum suspension force, raise this above the default 6000 if your suspension cannot
handle the weight of your vehcile.
|
void |
setMaxSuspensionForce(int wheel,
float maxSuspensionForce)
This vaue caps the maximum suspension force, raise this above the default 6000 if your suspension cannot
handle the weight of your vehcile.
|
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 |
updateWheels()
used internally
|
void |
write(com.jme3.export.JmeExporter ex) |
activate, addJoint, applyCentralForce, applyForce, applyImpulse, applyTorque, applyTorqueImpulse, clearForces, getAngularDamping, getAngularFactor, getAngularFactor, getAngularSleepingThreshold, getAngularVelocity, getAngularVelocity, getCcdMotionThreshold, getCcdSquareMotionThreshold, getCcdSweptSphereRadius, getFriction, getGravity, getGravity, getJoints, getLinearDamping, getLinearFactor, getLinearSleepingThreshold, getLinearVelocity, getLinearVelocity, getMass, getMotionState, getPhysicsLocation, getPhysicsLocation, getPhysicsRotation, getPhysicsRotation, getPhysicsRotationMatrix, getPhysicsRotationMatrix, getRestitution, isActive, isInWorld, isKinematic, preRebuild, rebuildRigidBody, removeJoint, setAngularDamping, setAngularFactor, setAngularFactor, setAngularSleepingThreshold, setAngularVelocity, setCcdMotionThreshold, setCcdSweptSphereRadius, setCollisionShape, setDamping, setFriction, setGravity, setKinematic, setLinearDamping, setLinearFactor, setLinearSleepingThreshold, setLinearVelocity, setMass, setPhysicsLocation, setPhysicsRotation, setPhysicsRotation, setRestitution, setSleepingThresholdsaddCollideWithGroup, attachCollisionShape, finalizeNative, getCollideWithGroups, getCollisionGroup, getCollisionShape, getObjectId, getUserObject, initUserPointer, removeCollideWithGroup, setCollideWithGroups, setCollisionGroup, setUserObjectprotected long vehicleId
protected long rayCasterId
protected VehicleTuning tuning
protected java.util.ArrayList<VehicleWheel> wheels
protected PhysicsSpace physicsSpace
public PhysicsVehicle()
public PhysicsVehicle(CollisionShape shape)
public PhysicsVehicle(CollisionShape shape, float mass)
public void updateWheels()
public void applyWheelTransforms()
protected void postRebuild()
postRebuild in class PhysicsRigidBodypublic void createVehicle(PhysicsSpace space)
public VehicleWheel addWheel(com.jme3.math.Vector3f connectionPoint, com.jme3.math.Vector3f direction, com.jme3.math.Vector3f axle, float suspensionRestLength, float wheelRadius, boolean isFrontWheel)
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)public VehicleWheel addWheel(com.jme3.scene.Spatial spat, com.jme3.math.Vector3f connectionPoint, com.jme3.math.Vector3f direction, com.jme3.math.Vector3f axle, float suspensionRestLength, float wheelRadius, boolean isFrontWheel)
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)public void removeWheel(int wheel)
wheel - public VehicleWheel getWheel(int wheel)
wheel - the wheel indexpublic int getNumWheels()
public float getFrictionSlip()
public void setFrictionSlip(float frictionSlip)
frictionSlip - the frictionSlip to setpublic void setFrictionSlip(int wheel,
float frictionSlip)
wheel - frictionSlip - public void setRollInfluence(int wheel,
float rollInfluence)
public float getMaxSuspensionTravelCm()
public void setMaxSuspensionTravelCm(float maxSuspensionTravelCm)
maxSuspensionTravelCm - the maxSuspensionTravelCm to setpublic void setMaxSuspensionTravelCm(int wheel,
float maxSuspensionTravelCm)
wheel - maxSuspensionTravelCm - public float getMaxSuspensionForce()
public void setMaxSuspensionForce(float maxSuspensionForce)
maxSuspensionForce - public void setMaxSuspensionForce(int wheel,
float maxSuspensionForce)
wheel - maxSuspensionForce - public float getSuspensionCompression()
public void setSuspensionCompression(float suspensionCompression)
suspensionCompression - the suspensionCompression to setpublic void setSuspensionCompression(int wheel,
float suspensionCompression)
wheel - suspensionCompression - public float getSuspensionDamping()
public void setSuspensionDamping(float suspensionDamping)
suspensionDamping - the suspensionDamping to setpublic void setSuspensionDamping(int wheel,
float suspensionDamping)
wheel - suspensionDamping - public float getSuspensionStiffness()
public void setSuspensionStiffness(float suspensionStiffness)
suspensionStiffness - public void setSuspensionStiffness(int wheel,
float suspensionStiffness)
wheel - suspensionStiffness - public void resetSuspension()
public void accelerate(float force)
force - the forcepublic void accelerate(int wheel,
float force)
wheel - the wheel to apply the force onforce - the forcepublic void steer(float value)
value - the steering angle of the front wheels (Pi = 360deg)public void steer(int wheel,
float value)
wheel - the wheel to set the steering onvalue - the steering angle of the front wheels (Pi = 360deg)public void brake(float force)
force - the forcepublic void brake(int wheel,
float force)
wheel - the wheel to apply the force onforce - the forcepublic float getCurrentVehicleSpeedKmHour()
public com.jme3.math.Vector3f getForwardVector(com.jme3.math.Vector3f vector)
vector - public long getVehicleId()
public void read(com.jme3.export.JmeImporter im)
throws java.io.IOException
read in interface com.jme3.export.Savableread in class PhysicsRigidBodyjava.io.IOExceptionpublic void write(com.jme3.export.JmeExporter ex)
throws java.io.IOException
write in interface com.jme3.export.Savablewrite in class PhysicsRigidBodyjava.io.IOExceptionprotected void finalize()
throws java.lang.Throwable
finalize in class PhysicsCollisionObjectjava.lang.Throwable