Class PxController

java.lang.Object
physx.NativeObject
physx.character.PxController
Direct Known Subclasses:
PxBoxController, PxCapsuleController

public class PxController extends NativeObject
Base class for character controllers.
See Also:
  • Field Details

    • SIZEOF

      public static final int SIZEOF
    • ALIGNOF

      public static final int ALIGNOF
      See Also:
  • Constructor Details

    • PxController

      protected PxController()
    • PxController

      protected PxController(long address)
  • Method Details

    • wrapPointer

      public static PxController wrapPointer(long address)
    • arrayGet

      public static PxController arrayGet(long baseAddress, int index)
    • getType

      public PxControllerShapeTypeEnum getType()
      Return the type of controller
    • release

      public void release()
      Releases the controller.
    • move

      public PxControllerCollisionFlags move(PxVec3 disp, float minDist, float elapsedTime, PxControllerFilters filters)
      Moves the character using a "collide-and-slide" algorithm.
      Parameters:
      disp - Displacement vector
      minDist - The minimum travelled distance to consider. If travelled distance is smaller, the character doesn't move. This is used to stop the recursive motion algorithm when remaining distance to travel is small.
      elapsedTime - Time elapsed since last call
      filters - User-defined filters for this move
      Returns:
      Collision flags, collection of ::PxControllerCollisionFlags
    • move

      public PxControllerCollisionFlags move(PxVec3 disp, float minDist, float elapsedTime, PxControllerFilters filters, PxObstacleContext obstacles)
      Moves the character using a "collide-and-slide" algorithm.
      Parameters:
      disp - Displacement vector
      minDist - The minimum travelled distance to consider. If travelled distance is smaller, the character doesn't move. This is used to stop the recursive motion algorithm when remaining distance to travel is small.
      elapsedTime - Time elapsed since last call
      filters - User-defined filters for this move
      obstacles - Potential additional obstacles the CCT should collide with.
      Returns:
      Collision flags, collection of ::PxControllerCollisionFlags
    • setPosition

      public boolean setPosition(PxExtendedVec3 position)
      Sets controller's position.

      The position controlled by this function is the center of the collision shape.

      \warning This is a 'teleport' function, it doesn't check for collisions. \warning The character's position must be such that it does not overlap the static geometry.

      To move the character under normal conditions use the #move() function.

      Parameters:
      position - The new (center) positon for the controller.
      Returns:
      Currently always returns true.
      See Also:
    • getPosition

      public PxExtendedVec3 getPosition()
      Retrieve the raw position of the controller.

      The position retrieved by this function is the center of the collision shape. To retrieve the bottom position of the shape, a.k.a. the foot position, use the getFootPosition() function.

      The position is updated by calls to move(). Calling this method without calling move() will return the last position or the initial position of the controller.

      Returns:
      The controller's center position
      See Also:
    • setFootPosition

      public boolean setFootPosition(PxExtendedVec3 position)
      Set controller's foot position.

      The position controlled by this function is the bottom of the collision shape, a.k.a. the foot position.

      Note: The foot position takes the contact offset into account

      \warning This is a 'teleport' function, it doesn't check for collisions.

      To move the character under normal conditions use the #move() function.

      Parameters:
      position - The new (bottom) positon for the controller.
      Returns:
      Currently always returns true.
      See Also:
    • getFootPosition

      public PxExtendedVec3 getFootPosition()
      Retrieve the "foot" position of the controller, i.e. the position of the bottom of the CCT's shape.

      Note: The foot position takes the contact offset into account

      Returns:
      The controller's foot position
      See Also:
    • getActor

      public PxRigidDynamic getActor()
      Get the rigid body actor associated with this controller (see PhysX documentation). The behavior upon manually altering this actor is undefined, you should primarily use it for reading const properties.
      Returns:
      the actor associated with the controller.
    • setStepOffset

      public void setStepOffset(float offset)
      The step height.
      Parameters:
      offset - The new step offset for the controller.
    • getStepOffset

      public float getStepOffset()
      Retrieve the step height.
      Returns:
      The step offset for the controller.
      See Also:
    • setNonWalkableMode

      public void setNonWalkableMode(PxControllerNonWalkableModeEnum flag)
      Sets the non-walkable mode for the CCT.
      Parameters:
      flag - The new value of the non-walkable mode.
    • getNonWalkableMode

      public PxControllerNonWalkableModeEnum getNonWalkableMode()
      Retrieves the non-walkable mode for the CCT.
      Returns:
      The current non-walkable mode.
    • getContactOffset

      public float getContactOffset()
      Retrieve the contact offset.
      Returns:
      The contact offset for the controller.
    • setContactOffset

      public void setContactOffset(float offset)
      Sets the contact offset.
      Parameters:
      offset - The contact offset for the controller.
    • getUpDirection

      public PxVec3 getUpDirection()
      Retrieve the 'up' direction.
      Returns:
      The up direction for the controller.
    • setUpDirection

      public void setUpDirection(PxVec3 up)
      Sets the 'up' direction.
      Parameters:
      up - The up direction for the controller.
    • getSlopeLimit

      public float getSlopeLimit()
      Retrieve the slope limit.
      Returns:
      The slope limit for the controller.
    • setSlopeLimit

      public void setSlopeLimit(float slopeLimit)
      Sets the slope limit.

      Note: This feature can not be enabled at runtime, i.e. if the slope limit is zero when creating the CCT (which disables the feature) then changing the slope limit at runtime will not have any effect, and the call will be ignored.

      Parameters:
      slopeLimit - The slope limit for the controller.
    • invalidateCache

      public void invalidateCache()
      Flushes internal geometry cache.

      The character controller uses caching in order to speed up collision testing. The cache is automatically flushed when a change to static objects is detected in the scene. For example when a static shape is added, updated, or removed from the scene, the cache is automatically invalidated.

      However there may be situations that cannot be automatically detected, and those require manual invalidation of the cache. Currently the user must call this when the filtering behavior changes (the PxControllerFilters parameter of the PxController::move call). While the controller in principle could detect a change in these parameters, it cannot detect a change in the behavior of the filtering function.

      See Also:
    • getScene

      public PxScene getScene()
      Retrieve the scene associated with the controller.
      Returns:
      The physics scene
    • getUserData

      public NativeObject getUserData()
      Returns the user data associated with this controller.
      Returns:
      The user pointer associated with the controller.
    • setUserData

      public void setUserData(NativeObject userData)
      Sets the user data associated with this controller.
      Parameters:
      userData - The user pointer associated with the controller.
    • getState

      public void getState(PxControllerState state)
      Returns information about the controller's internal state.
      Parameters:
      state - The controller's internal state
      See Also:
    • getStats

      public void getStats(PxControllerStats stats)
      Returns the controller's internal statistics.
      Parameters:
      stats - The controller's internal statistics
      See Also:
    • resize

      public void resize(float height)
      Resizes the controller.

      This function attempts to resize the controller to a given size, while making sure the bottom position of the controller remains constant. In other words the function modifies both the height and the (center) position of the controller. This is a helper function that can be used to implement a 'crouch' functionality for example.

      Parameters:
      height - Desired controller's height