public class BetterCharacterControl extends AbstractPhysicsControl implements PhysicsTickListener, com.jme3.util.clone.JmeCloneable
| Modifier and Type | Field and Description |
|---|---|
protected boolean |
ducked |
protected float |
duckedFactor |
protected float |
height |
protected boolean |
jump |
protected com.jme3.math.Vector3f |
jumpForce |
protected com.jme3.math.Vector3f |
localForward
Local absolute z-forward direction, derived from gravity and UNIT_Z,
updated continuously when gravity changes.
|
protected com.jme3.math.Quaternion |
localForwardRotation
Local z-forward quaternion for the "local absolute" z-forward direction.
|
protected com.jme3.math.Vector3f |
localLeft
Local left direction, derived from up and forward.
|
protected com.jme3.math.Vector3f |
localUp
Local up direction, derived from gravity.
|
protected com.jme3.math.Vector3f |
location
Stores final spatial location, corresponds to RigidBody location.
|
protected static java.util.logging.Logger |
logger |
protected float |
mass |
protected boolean |
onGround |
protected float |
physicsDamping |
protected float |
radius |
protected PhysicsRigidBody |
rigidBody |
protected com.jme3.math.Vector3f |
rotatedViewDirection |
protected com.jme3.math.Quaternion |
rotation
Stores final spatial rotation, is a z-forward rotation based on the view
direction and the current local x/z plane.
|
protected com.jme3.math.Vector3f |
scale |
protected com.jme3.math.Vector3f |
velocity |
protected com.jme3.math.Vector3f |
viewDirection
Is a z-forward vector based on the view direction and the current local
x/z plane.
|
protected com.jme3.math.Vector3f |
walkDirection |
protected boolean |
wantToUnDuck |
added, applyLocal, enabled, space, spatial| Constructor and Description |
|---|
BetterCharacterControl()
Only used for serialization, do not use this constructor.
|
BetterCharacterControl(float radius,
float height,
float mass)
Creates a new character with the given properties.
|
| Modifier and Type | Method and Description |
|---|---|
protected void |
addPhysics(PhysicsSpace space)
This is implemented from AbstractPhysicsControl and called when the
control is supposed to add all objects to the physics space.
|
protected void |
calculateNewForward(com.jme3.math.Quaternion rotation,
com.jme3.math.Vector3f direction,
com.jme3.math.Vector3f worldUpVector)
This method works similar to Camera.lookAt but where lookAt sets the
priority on the direction, this method sets the priority on the up vector
so that the result direction vector and rotation is guaranteed to be
perpendicular to the up vector.
|
protected boolean |
checkCanUnDuck()
This checks if the character can go from ducked to unducked state by
doing a ray test.
|
protected void |
checkOnGround()
This checks if the character is on the ground by doing a ray test.
|
com.jme3.scene.control.Control |
cloneForSpatial(com.jme3.scene.Spatial spatial) |
protected void |
createSpatialData(com.jme3.scene.Spatial spat)
Called when the control is added to a new spatial, create any
spatial-dependent data here.
|
float |
getDuckedFactor()
Gets the height multiplication factor for ducking.
|
protected float |
getFinalHeight()
Gets the scaled height.
|
protected float |
getFinalRadius()
Gets the scaled radius.
|
com.jme3.math.Vector3f |
getGravity()
Get the current gravity of the character.
|
com.jme3.math.Vector3f |
getGravity(com.jme3.math.Vector3f store)
Get the current gravity of the character.
|
com.jme3.math.Vector3f |
getJumpForce()
Gets the current jump force.
|
float |
getPhysicsDamping()
Gets how much the physics forces in the local x/z plane should be
dampened.
|
protected CollisionShape |
getShape()
Gets a new collision shape based on the current scale parameter.
|
com.jme3.math.Vector3f |
getVelocity()
Get the current linear velocity along the three axes of the character.
|
com.jme3.math.Vector3f |
getViewDirection()
Gets the current view direction, note this doesn't need to correspond
with the spatials forward direction.
|
com.jme3.math.Vector3f |
getWalkDirection()
Gets the current walk direction and speed of the character.
|
boolean |
isDucked()
Check if the character is ducking, either due to user input or due to
unducking being impossible at the moment (obstacle above).
|
boolean |
isOnGround()
Check if the character is on the ground.
|
java.lang.Object |
jmeClone() |
void |
jump()
Makes the character jump with the set jump force.
|
void |
physicsTick(PhysicsSpace space,
float tpf)
Used internally, don't call manually
|
void |
prePhysicsTick(PhysicsSpace space,
float tpf)
Used internally, don't call manually
|
void |
read(com.jme3.export.JmeImporter im) |
protected void |
removePhysics(PhysicsSpace space)
This is implemented from AbstractPhysicsControl and called when the
control is supposed to remove all objects from the physics space.
|
protected void |
removeSpatialData(com.jme3.scene.Spatial spat)
Called when the control is removed from a spatial, remove any
spatial-dependent data here.
|
void |
render(com.jme3.renderer.RenderManager rm,
com.jme3.renderer.ViewPort vp) |
void |
resetForward(com.jme3.math.Vector3f vec)
Realign the local forward vector to given direction vector, if null is
supplied Vector3f.UNIT_Z is used.
|
void |
setDucked(boolean enabled)
Toggle character ducking.
|
void |
setDuckedFactor(float factor)
Sets the height multiplication factor for ducking.
|
void |
setGravity(com.jme3.math.Vector3f gravity)
Set the gravity for this character.
|
protected void |
setHeightPercent(float percent)
This actually sets a new collision shape to the character to change the
height of the capsule.
|
void |
setJumpForce(com.jme3.math.Vector3f jumpForce)
Set the jump force as a Vector3f.
|
void |
setPhysicsDamping(float physicsDamping)
Sets how much the physics forces in the local x/z plane should be
dampened.
|
protected void |
setPhysicsLocation(com.jme3.math.Vector3f vec)
This is implemented from AbstractPhysicsControl and called when the
spatial is attached for example.
|
protected void |
setPhysicsRotation(com.jme3.math.Quaternion quat)
This is implemented from AbstractPhysicsControl and called when the
spatial is attached for example.
|
void |
setViewDirection(com.jme3.math.Vector3f vec)
Sets the view direction for the character.
|
void |
setWalkDirection(com.jme3.math.Vector3f vec)
Sets the walk direction of the character.
|
void |
update(float tpf) |
protected void |
updateLocalCoordinateSystem()
Updates the local coordinate system from the localForward and localUp
vectors, adapts localForward, sets localForwardRotation quaternion to
local z-forward rotation.
|
protected void |
updateLocalViewDirection()
Updates the local x/z-flattened view direction and the corresponding
rotation quaternion for the spatial.
|
void |
warp(com.jme3.math.Vector3f vec)
Move the character somewhere.
|
void |
write(com.jme3.export.JmeExporter ex) |
applyPhysicsTransform, cloneFields, getPhysicsSpace, getSpatialRotation, getSpatialTranslation, isApplyPhysicsLocal, isEnabled, setApplyPhysicsLocal, setEnabled, setPhysicsSpace, setSpatialprotected static final java.util.logging.Logger logger
protected PhysicsRigidBody rigidBody
protected float radius
protected float height
protected float mass
protected float duckedFactor
protected final com.jme3.math.Vector3f localUp
protected final com.jme3.math.Vector3f localForward
protected final com.jme3.math.Vector3f localLeft
protected final com.jme3.math.Quaternion localForwardRotation
protected final com.jme3.math.Vector3f viewDirection
protected final com.jme3.math.Vector3f location
protected final com.jme3.math.Quaternion rotation
protected final com.jme3.math.Vector3f rotatedViewDirection
protected final com.jme3.math.Vector3f walkDirection
protected final com.jme3.math.Vector3f jumpForce
protected float physicsDamping
protected final com.jme3.math.Vector3f scale
protected final com.jme3.math.Vector3f velocity
protected boolean jump
protected boolean onGround
protected boolean ducked
protected boolean wantToUnDuck
public BetterCharacterControl()
public BetterCharacterControl(float radius,
float height,
float mass)
radius - height - mass - public void update(float tpf)
update in interface com.jme3.scene.control.Controlupdate in class AbstractPhysicsControlpublic void render(com.jme3.renderer.RenderManager rm,
com.jme3.renderer.ViewPort vp)
render in interface com.jme3.scene.control.Controlrender in class AbstractPhysicsControlpublic void prePhysicsTick(PhysicsSpace space, float tpf)
prePhysicsTick in interface PhysicsTickListenerspace - tpf - public void physicsTick(PhysicsSpace space, float tpf)
physicsTick in interface PhysicsTickListenerspace - tpf - public void warp(com.jme3.math.Vector3f vec)
vec - The new character location.public void jump()
public void setJumpForce(com.jme3.math.Vector3f jumpForce)
jumpForce - The new jump forcepublic com.jme3.math.Vector3f getJumpForce()
public boolean isOnGround()
public void setDucked(boolean enabled)
enabled - public boolean isDucked()
public void setDuckedFactor(float factor)
factor - The factor by which the height should be multiplied when
duckingpublic float getDuckedFactor()
public void setWalkDirection(com.jme3.math.Vector3f vec)
vec - The movement direction and speed in m/spublic com.jme3.math.Vector3f getWalkDirection()
public void setViewDirection(com.jme3.math.Vector3f vec)
vec - public com.jme3.math.Vector3f getViewDirection()
public void resetForward(com.jme3.math.Vector3f vec)
vec - The new forward vector, has to be perpendicular to the current
gravity vector!public com.jme3.math.Vector3f getVelocity()
public void setGravity(com.jme3.math.Vector3f gravity)
gravity - public com.jme3.math.Vector3f getGravity()
public com.jme3.math.Vector3f getGravity(com.jme3.math.Vector3f store)
store - The vector to store the result inpublic void setPhysicsDamping(float physicsDamping)
physicsDamping - The dampening value, 0 = no dampening, 1 = no external force, default = 0.9public float getPhysicsDamping()
protected void setHeightPercent(float percent)
percent - protected void checkOnGround()
protected boolean checkCanUnDuck()
protected CollisionShape getShape()
protected float getFinalHeight()
protected float getFinalRadius()
protected void updateLocalCoordinateSystem()
protected void updateLocalViewDirection()
protected final void calculateNewForward(com.jme3.math.Quaternion rotation,
com.jme3.math.Vector3f direction,
com.jme3.math.Vector3f worldUpVector)
rotation - The rotation to set the result on or null to create a new
Quaternion, this will be set to the new "z-forward" rotation if not nulldirection - The direction to base the new look direction on, will be
set to the new directionworldUpVector - The up vector to use, the result direction will be
perpendicular to thisprotected void setPhysicsLocation(com.jme3.math.Vector3f vec)
setPhysicsLocation in class AbstractPhysicsControlvec - protected void setPhysicsRotation(com.jme3.math.Quaternion quat)
setPhysicsRotation in class AbstractPhysicsControlquat - protected void addPhysics(PhysicsSpace space)
addPhysics in class AbstractPhysicsControlspace - protected void removePhysics(PhysicsSpace space)
removePhysics in class AbstractPhysicsControlspace - protected void createSpatialData(com.jme3.scene.Spatial spat)
AbstractPhysicsControlcreateSpatialData in class AbstractPhysicsControlspat - The new spatial, guaranteed not to be nullprotected void removeSpatialData(com.jme3.scene.Spatial spat)
AbstractPhysicsControlremoveSpatialData in class AbstractPhysicsControlspat - The old spatial, guaranteed not to be nullpublic com.jme3.scene.control.Control cloneForSpatial(com.jme3.scene.Spatial spatial)
cloneForSpatial in interface com.jme3.scene.control.Controlpublic java.lang.Object jmeClone()
jmeClone in interface com.jme3.util.clone.JmeCloneablepublic void write(com.jme3.export.JmeExporter ex)
throws java.io.IOException
write in interface com.jme3.export.Savablewrite in class AbstractPhysicsControljava.io.IOExceptionpublic void read(com.jme3.export.JmeImporter im)
throws java.io.IOException
read in interface com.jme3.export.Savableread in class AbstractPhysicsControljava.io.IOException