Package com.jme3.bullet.control
Class CharacterControl
java.lang.Object
com.jme3.bullet.control.AbstractPhysicsControl
com.jme3.bullet.control.CharacterControl
- All Implemented Interfaces:
PhysicsControl
,com.jme3.export.Savable
,com.jme3.scene.control.Control
,com.jme3.util.clone.JmeCloneable
,Cloneable
A PhysicsControl to link a PhysicsCharacter to a Spatial.
-
Field Summary
Fields inherited from class com.jme3.bullet.control.AbstractPhysicsControl
added, logger
-
Constructor Summary
ModifierConstructorDescriptionprotected
No-argument constructor needed by SavableClassUtil.CharacterControl
(ConvexShape shape, float stepHeight) Instantiate an enabled Control with the specified CollisionShape and step height. -
Method Summary
Modifier and TypeMethodDescriptionprotected void
Add all managed physics objects to the PhysicsSpace.void
cloneFields
(com.jme3.util.clone.Cloner cloner, Object original) Callback fromCloner
to convert this shallow-cloned Control into a deep-cloned one, using the specified Cloner and original to resolve copied fields.protected void
createSpatialData
(com.jme3.scene.Spatial spatial) Create spatial-dependent data.Access the PhysicsCharacter managed by this Control.com.jme3.math.Vector3f
Copy the character's location.com.jme3.math.Vector3f
getViewDirection
(com.jme3.math.Vector3f storeResult) Copy the character's view direction.void
jump()
Jump in the "up" direction.boolean
onGround()
Test whether the character is on the ground.void
read
(com.jme3.export.JmeImporter importer) De-serialize this Control from the specified importer, for example when loading from a J3O file.protected void
Remove all managed physics objects from the PhysicsSpace.protected void
removeSpatialData
(com.jme3.scene.Spatial spatial) Destroy spatial-dependent data.void
setFallSpeed
(float speed) Alter this character's maximum fall speed (terminal velocity).void
setGravity
(float downwardAcceleration) Alter the character's gravitational acceleration.void
setJumpSpeed
(float speed) Alter the character's jump speed.void
setPhysicsLocation
(com.jme3.math.Vector3f location) Translate the PhysicsCharacter to the specified location.protected void
setPhysicsRotation
(com.jme3.math.Quaternion orientation) Rotate the PhysicsCharacter to the specified orientation.void
setViewDirection
(com.jme3.math.Vector3f direction) Alter the view direction.void
setWalkDirection
(com.jme3.math.Vector3f offset) Alter the character's walk offset.void
update
(float tpf) Update this Control.void
write
(com.jme3.export.JmeExporter exporter) Serialize this Control to the specified exporter, for example when saving to a J3O file.Methods inherited from class com.jme3.bullet.control.AbstractPhysicsControl
applyPhysicsTransform, cloneForSpatial, getPhysicsSpace, getSpatial, getSpatialRotation, getSpatialTranslation, isApplyPhysicsLocal, isEnabled, jmeClone, render, setApplyPhysicsLocal, setEnabled, setPhysicsSpace, setSpatial
-
Field Details
-
logger2
message logger for this class
-
-
Constructor Details
-
CharacterControl
protected CharacterControl()No-argument constructor needed by SavableClassUtil. -
CharacterControl
Instantiate an enabled Control with the specified CollisionShape and step height.- Parameters:
shape
- the desired shape (not null, alias created)stepHeight
- the maximum amount of normal vertical movement (in physics-space units)
-
-
Method Details
-
getCharacter
Access the PhysicsCharacter managed by this Control.- Returns:
- the pre-existing instance (not null)
-
getPhysicsLocation
public com.jme3.math.Vector3f getPhysicsLocation()Copy the character's location.- Returns:
- a new location vector (in physics-space coordinates, not null)
-
getViewDirection
public com.jme3.math.Vector3f getViewDirection(com.jme3.math.Vector3f storeResult) Copy the character's view direction. This need not agree with the spatial's forward direction.- Parameters:
storeResult
- storage for the result (modified if not null)- Returns:
- a direction vector (in physics-space coordinates, either the provided storage or a new vector, not null)
-
jump
public void jump()Jump in the "up" direction. -
onGround
public boolean onGround()Test whether the character is on the ground.- Returns:
- true if on the ground, otherwise false
-
setFallSpeed
public void setFallSpeed(float speed) Alter this character's maximum fall speed (terminal velocity).- Parameters:
speed
- the desired speed (in physics-space units per second, default=55)
-
setGravity
public void setGravity(float downwardAcceleration) Alter the character's gravitational acceleration.- Parameters:
downwardAcceleration
- the desired downward acceleration (in physics-space units per second squared, not null, default=29.4)
-
setJumpSpeed
public void setJumpSpeed(float speed) Alter the character's jump speed.- Parameters:
speed
- the desired speed (in physics-space units per second, default=10)
-
setViewDirection
public void setViewDirection(com.jme3.math.Vector3f direction) Alter the view direction.- Parameters:
direction
- the desired direction (in physics-space coordinates, not null, not zero)
-
setWalkDirection
public void setWalkDirection(com.jme3.math.Vector3f offset) Alter the character's walk offset. The offset must be perpendicular to the "up" direction. It will continue to be applied until altered again.- Parameters:
offset
- the desired position increment for each simulation step (in physics-space coordinates, not null, unaffected)
-
addPhysics
protected void addPhysics()Add all managed physics objects to the PhysicsSpace.- Specified by:
addPhysics
in classAbstractPhysicsControl
-
cloneFields
Callback fromCloner
to convert this shallow-cloned Control into a deep-cloned one, using the specified Cloner and original to resolve copied fields.- Specified by:
cloneFields
in interfacecom.jme3.util.clone.JmeCloneable
- Overrides:
cloneFields
in classAbstractPhysicsControl
- Parameters:
cloner
- the Cloner that's cloning this Control (not null, modified)original
- the instance from which this Control was shallow-cloned (not null, unaffected)
-
createSpatialData
protected void createSpatialData(com.jme3.scene.Spatial spatial) Create spatial-dependent data. Invoked when this Control is added to a Spatial.- Specified by:
createSpatialData
in classAbstractPhysicsControl
- Parameters:
spatial
- the controlled spatial (not null, alias created)
-
read
De-serialize this Control from the specified importer, for example when loading from a J3O file.- Specified by:
read
in interfacecom.jme3.export.Savable
- Overrides:
read
in classAbstractPhysicsControl
- Parameters:
importer
- (not null)- Throws:
IOException
- from the importer
-
removePhysics
protected void removePhysics()Remove all managed physics objects from the PhysicsSpace.- Specified by:
removePhysics
in classAbstractPhysicsControl
-
removeSpatialData
protected void removeSpatialData(com.jme3.scene.Spatial spatial) Destroy spatial-dependent data. Invoked when this Control is removed from its Spatial.- Specified by:
removeSpatialData
in classAbstractPhysicsControl
- Parameters:
spatial
- the Spatial to which this Control was added (unused)
-
setPhysicsLocation
public void setPhysicsLocation(com.jme3.math.Vector3f location) Translate the PhysicsCharacter to the specified location.- Specified by:
setPhysicsLocation
in classAbstractPhysicsControl
- Parameters:
location
- the desired location (not null, unaffected)
-
setPhysicsRotation
protected void setPhysicsRotation(com.jme3.math.Quaternion orientation) Rotate the PhysicsCharacter to the specified orientation.- Specified by:
setPhysicsRotation
in classAbstractPhysicsControl
- Parameters:
orientation
- the desired orientation (not null, unaffected)
-
update
public void update(float tpf) Update this Control. Invoked once per frame during the logical-state update, provided the Control is added to a scene. Do not invoke directly from user code.- Parameters:
tpf
- the time interval between frames (in seconds, ≥0)
-
write
Serialize this Control to the specified exporter, for example when saving to a J3O file.- Specified by:
write
in interfacecom.jme3.export.Savable
- Overrides:
write
in classAbstractPhysicsControl
- Parameters:
exporter
- (not null)- Throws:
IOException
- from the exporter
-