Class CharacterVirtual

All Implemented Interfaces:
ConstCharacterBase, ConstCharacterVirtual, ConstJoltPhysicsObject, RefTarget, AutoCloseable, Comparable<JoltPhysicsObject>

public class CharacterVirtual extends CharacterBase implements ConstCharacterVirtual
A character implemented without a rigid body.
  • Constructor Details

    • CharacterVirtual

      public CharacterVirtual(long characterVa, PhysicsSystem physicsSystem)
      Instantiate a character with the specified native object assigned but not owned.

      For use in custom contact listeners.

      Parameters:
      characterVa - the virtual address of the native object to assign (not zero)
      physicsSystem - where to add the body (not null)
    • CharacterVirtual

      public CharacterVirtual(ConstCharacterVirtualSettings settings, RVec3Arg location, QuatArg orientation, long userData, PhysicsSystem system)
      Instantiate a character with a new native object assigned.
      Parameters:
      settings - the settings to use (not null, unaffected)
      location - the desired initial location (in system coordinates, not null, unaffected)
      orientation - the desired initial orientation (in system coordinates, not null, unaffected)
      userData - the desired user-data value
      system - where to add the body (not null)
  • Method Details

    • extendedUpdate

      public void extendedUpdate(float deltaTime, Vec3Arg gravity, ExtendedUpdateSettings settings, BroadPhaseLayerFilter bpFilter, ObjectLayerFilter olFilter, BodyFilter bodyFilter, ShapeFilter shapeFilter, TempAllocator allocator)
      Apply a combination of Update, StickToFloor, and WalkStairs.
      Parameters:
      deltaTime - the time step to simulate
      gravity - the gravity acceleration vector (in meters per second squared, not null, unaffected)
      settings - settings to use (not null, unaffected)
      bpFilter - to test whether the character collides with a broad-phase layer (not null, unaffected)
      olFilter - to test whether the character collides with an object layer (not null, unaffected)
      bodyFilter - to test whether the character collides with a body (not null, unaffected)
      shapeFilter - to test whether the character collides with a shape (not null, unaffected)
      allocator - for temporary allocations (not null)
    • getCharacterVsCharacterCollision

      public CharacterVsCharacterCollision getCharacterVsCharacterCollision()
      Access the char-vs-char collision interface.
      Returns:
      the pre-existing object, or null if none
    • getListener

      public CharacterContactListener getListener()
      Access the (application-provided) contact listener.
      Returns:
      the pre-existing instance, or null if none
    • setCharacterVsCharacterCollision

      public void setCharacterVsCharacterCollision(CharacterVsCharacterCollision cvcInterface)
      Replace the char-vs-char collision interface.
      Parameters:
      cvcInterface - the desired interface (not null)
    • setEnhancedInternalEdgeRemoval

      public void setEnhancedInternalEdgeRemoval(boolean enable)
      Enable or disable enhanced internal edge removal.
      Parameters:
      enable - true to enable, false to disable (default=false)
    • setHitReductionCosMaxAngle

      public void setHitReductionCosMaxAngle(float cosine)
      Alter the maximum angle for merging during hit reduction.
      Parameters:
      cosine - the cosine of the desired maximum angle, or -1 to disable hit reduction (default=1)
    • setInnerBodyShape

      public void setInnerBodyShape(ConstShape shape)
      Alter the shape of the inner body. Invoke this after a successful invocation of setShape().
      Parameters:
      shape - the desired shape (not null, unaffected, default=?)
    • setLinearVelocity

      public void setLinearVelocity(Vec3Arg velocity)
      Alter the character's linear velocity.
      Parameters:
      velocity - the desired velocity vector (meters per second in system coordinates, default=(0,0,0))
    • setListener

      public void setListener(CharacterContactListener listener)
      Replace the contact listener.
      Parameters:
      listener - the desired listener
    • setMass

      public void setMass(float mass)
      Alter the character's mass.
      Parameters:
      mass - the desired mass (in kilograms, default=70)
    • setMaxNumHits

      public void setMaxNumHits(int maxHits)
      Alter the maximum number of hits to be collected.
      Parameters:
      maxHits - the desired limit (≥0, default=256)
    • setMaxStrength

      public void setMaxStrength(float force)
      Alter the maximum force applied to bodies.
      Parameters:
      force - the desired force limit (in Newtons, default=100)
    • setPenetrationRecoverySpeed

      public void setPenetrationRecoverySpeed(float fraction)
      Alter how quickly penetration is resolved.
      Parameters:
      fraction - the desired resolution fraction (0→never resolved, 1→all in one update, default=1)
    • setPosition

      public void setPosition(RVec3Arg location)
      Relocate the character.
      Parameters:
      location - the desired location (in system coordinates, default=(0,0,0))
    • setRotation

      public void setRotation(QuatArg orientation)
      Re-orient the character.
      Parameters:
      orientation - the desired orientation (in system coordinates, default=(0,0,0,1))
    • setShape

      public boolean setShape(ConstShape shape, float maxPenetrationDepth, BroadPhaseLayerFilter broadPhaseLayerFilter, ObjectLayerFilter objectLayerFilter, BodyFilter bodyFilter, ShapeFilter shapeFilter, TempAllocator allocator)
      Alter the character's shape.
      Parameters:
      shape - the desired shape (not null)
      maxPenetrationDepth - the maximum acceptable penetration after the alteration, or Float.MAX_VALUE to skip the check
      broadPhaseLayerFilter - the broadphase filter used to test for collisions (not null)
      objectLayerFilter - the object-layer filter used to test for collisions (not null)
      bodyFilter - the body filter used to test for collisions (not null)
      shapeFilter - the shape filter used to test for collisions (not null)
      allocator - the desired allocator (not null)
      Returns:
      true if successful, otherwise false
    • setShapeOffset

      public void setShapeOffset(Vec3Arg offset)
      Alter the shape offset.
      Parameters:
      offset - the desired offset (in local coordinates, default=(0,0,0))
    • setUserData

      public void setUserData(long userData)
      Alter the user data.
      Parameters:
      userData - the desired value
    • updateGroundVelocity

      public void updateGroundVelocity()
      Update the estimated ground velocity.
    • toRef

      public CharacterVirtualRef toRef()
      Create a counted reference to the native CharacterVirtual.
      Specified by:
      toRef in interface RefTarget
      Returns:
      a new JVM object with a new native object assigned
    • cancelVelocityTowardsSteepSlopes

      public Vec3 cancelVelocityTowardsSteepSlopes(Vec3Arg desiredVelocity)
      Convert the specified velocity to one that won't climb steep slopes. The character is unaffected.
      Specified by:
      cancelVelocityTowardsSteepSlopes in interface ConstCharacterVirtual
      Parameters:
      desiredVelocity - velocity vector (in system coordinates, not null, unaffected)
      Returns:
      a new velocity vector (in system coordinates)
    • canWalkStairs

      public boolean canWalkStairs(Vec3Arg desiredVelocity)
      Test whether the character has moved onto a steep slope. The character is unaffected.
      Specified by:
      canWalkStairs in interface ConstCharacterVirtual
      Parameters:
      desiredVelocity - velocity vector (in system coordinates, not null, unaffected)
      Returns:
      true if too step to walk, otherwise false
    • getActiveContacts

      public ConstContact[] getActiveContacts()
      Copy the list of active contacts. The character is unaffected.
      Specified by:
      getActiveContacts in interface ConstCharacterVirtual
      Returns:
      a new array of new objects
    • getCenterOfMassPosition

      public RVec3 getCenterOfMassPosition()
      Calculate the location of the character's center of mass. The character is unaffected.
      Specified by:
      getCenterOfMassPosition in interface ConstCharacterVirtual
      Returns:
      a new location vector (in system coordinates)
    • getCenterOfMassTransform

      public RMat44 getCenterOfMassTransform()
      Calculate the local-to-system transform of the character's center of mass. The character is unaffected.
      Specified by:
      getCenterOfMassTransform in interface ConstCharacterVirtual
      Returns:
      a new coordinate transform matrix
    • getCharacterPadding

      public float getCharacterPadding()
      Return the thickness of the character's padding. The character is unaffected.
      Specified by:
      getCharacterPadding in interface ConstCharacterVirtual
      Returns:
      the thickness (in meters)
    • getEnhancedInternalEdgeRemoval

      public boolean getEnhancedInternalEdgeRemoval()
      Test whether enhanced internal edge removal is enabled. The character is unaffected.
      Specified by:
      getEnhancedInternalEdgeRemoval in interface ConstCharacterVirtual
      Returns:
      true if enabled, otherwise false
    • getHitReductionCosMaxAngle

      public float getHitReductionCosMaxAngle()
      Return the maximum angle for merging during hit reduction. The character is unaffected.
      Specified by:
      getHitReductionCosMaxAngle in interface ConstCharacterVirtual
      Returns:
      the cosine of the maximum angle, or -1 if hit reduction is disabled
    • getId

      public int getId()
      Return the character's ID. The character is unaffected. (native method: GetID)
      Specified by:
      getId in interface ConstCharacterVirtual
      Returns:
      a CharacterId value
    • getInnerBodyId

      public int getInnerBodyId()
      Return the ID of the inner body. The character is unaffected. (native method: GetInnerBodyID)
      Specified by:
      getInnerBodyId in interface ConstCharacterVirtual
      Returns:
      the BodyID value
    • getLinearVelocity

      public Vec3 getLinearVelocity()
      Copy the linear velocity of the character. The character is unaffected.
      Specified by:
      getLinearVelocity in interface ConstCharacterVirtual
      Returns:
      a new velocity vector (meters per second in system coordinates)
    • getMass

      public float getMass()
      Return the character's mass. The character is unaffected.
      Specified by:
      getMass in interface ConstCharacterVirtual
      Returns:
      the mass (in kilograms)
    • getMaxHitsExceeded

      public boolean getMaxHitsExceeded()
      Test whether the last collision check discarded one or more hits. The character is unaffected.
      Specified by:
      getMaxHitsExceeded in interface ConstCharacterVirtual
      Returns:
      true if discarded hits, otherwise false
    • getMaxNumHits

      public int getMaxNumHits()
      Return the maximum number of hits to be collected. The character is unaffected.
      Specified by:
      getMaxNumHits in interface ConstCharacterVirtual
      Returns:
      the limit (≥0)
    • getMaxStrength

      public float getMaxStrength()
      Return the maximum force applied to other bodies. The character is unaffected.
      Specified by:
      getMaxStrength in interface ConstCharacterVirtual
      Returns:
      the force (in Newtons)
    • getPenetrationRecoverySpeed

      public float getPenetrationRecoverySpeed()
      Return how quickly penetration is resolved. The character is unaffected.
      Specified by:
      getPenetrationRecoverySpeed in interface ConstCharacterVirtual
      Returns:
      the resolution fraction (0=never resolved, 1=all in one update)
    • getPosition

      public RVec3 getPosition()
      Copy the location of the character. The character is unaffected.
      Specified by:
      getPosition in interface ConstCharacterVirtual
      Returns:
      a new location vector (in system coordinates)
    • getPositionAndRotation

      public void getPositionAndRotation(RVec3 storeLocation, Quat storeOrientation)
      Copy the position of the character. The character is unaffected.
      Specified by:
      getPositionAndRotation in interface ConstCharacterVirtual
      Parameters:
      storeLocation - storage for the location (in system coordinates, not null, modified)
      storeOrientation - storage for the orientation (in system coordinates, not null, modified)
    • getRotation

      public Quat getRotation()
      Copy the orientation of the character. The character is unaffected.
      Specified by:
      getRotation in interface ConstCharacterVirtual
      Returns:
      a new rotation quaternion (in system coordinates)
    • getShapeOffset

      public Vec3 getShapeOffset()
      Copy the local offset applied to the shape. The character is unaffected.
      Specified by:
      getShapeOffset in interface ConstCharacterVirtual
      Returns:
      a new offset vector (in local coordinates)
    • getTransformedShape

      public TransformedShape getTransformedShape()
      Return a TransformedShape that represents the volume occupied by the character. The character is unaffected.
      Specified by:
      getTransformedShape in interface ConstCharacterVirtual
      Returns:
      a new object
    • getUserData

      public long getUserData()
      Return the character's user data: can be used for anything. The character is unaffected.
      Specified by:
      getUserData in interface ConstCharacterVirtual
      Returns:
      the value
    • getWorldTransform

      public RMat44 getWorldTransform()
      Calculate the character's local-to-system coordinate transform. The character is unaffected.
      Specified by:
      getWorldTransform in interface ConstCharacterVirtual
      Returns:
      a new transform matrix
    • hasCollidedWith

      public boolean hasCollidedWith(int bodyId)
      Test whether the character is in contact with or collided with the specified body during the previous time step. The character is unaffected.
      Specified by:
      hasCollidedWith in interface ConstCharacterVirtual
      Parameters:
      bodyId - the ID of the body to test against
      Returns:
      true if contact or collision, otherwise false
    • hasCollidedWith

      public boolean hasCollidedWith(ConstCharacterVirtual otherCharacter)
      Test whether the character is in contact with or has collided with the specified character during the previous time step. The current character is unaffected.
      Specified by:
      hasCollidedWith in interface ConstCharacterVirtual
      Parameters:
      otherCharacter - the character to test against (not null, unaffected)
      Returns:
      true if contact or collision, otherwise false
    • toRefC

      public CharacterVirtualRefC toRefC()
      Create a counted reference to the native CharacterVirtual.
      Specified by:
      toRefC in interface ConstCharacterVirtual
      Returns:
      a new JVM object with a new native object assigned