Char Component. Describes the properties of a Jolt Virtual Character.

Hierarchy (view full)

Accessors

  • get backFaceMode(): number
  • When colliding with back faces, the character will not be able to move through back facing triangles. Use this if you have triangles that need to collide on both sides. Following constants available:

    BFM_IGNORE_BACK_FACES
    
    BFM_COLLIDE_BACK_FACES
    

    Returns number

    Constant number, representing the back face collision mode.

    Default Value

    BFM_COLLIDE_BACK_FACES
    
  • get characterPadding(): number
  • How far we try to stay away from the geometry. This ensures that the sweep will hit as little as possible lowering the collision cost and reducing the risk of getting stuck.

    Returns number

    Padding distance.

    Default Value

    0.02 (meters)
    
  • get convexRadius(): number
  • Internally the convex radius will be subtracted from the half extent, so the total size will not grow with the convex radius. You can increase this value to make the edges of the collision shape rounded.

    Note:

    • Only used by shapes with sharp edges: SHAPE_BOX and SHAPE_CYLINDER.
    • Cannot be changed after the shape is created.

    Returns number

    Number, representing the convex radius.

    Default Value

    0.05 (m)
    
  • get debugDraw(): boolean
  • Specifies, whether to debug draw the collision shape.

    Returns boolean

    Boolean, telling if the collision shape should be drawn using lines.

    Default Value

    false
    
  • set debugDraw(bool): void
  • Allows to turn on/off debug draw for this body. Only works with a debug build.

    Parameters

    • bool: boolean

      Boolean to enable/disable a debug draw.

    Returns void

  • get debugDrawDepth(): boolean
  • Returns boolean

    Default Value

    true
    
  • set debugDrawDepth(bool): void
  • If debugDraw is enabled, this will specify whether to consider scene depth or not. If set to false, the debug lines will be drawn on top of everything, through other meshes.

    Parameters

    • bool: boolean

      Boolean, telling whether to consider scene depth.

    Returns void

  • get density(): number
  • Density of the object. Affects the mass of the object, when BodyComponent.overrideMassProperties is set to OMP_CALCULATE_MASS_AND_INERTIA (default, which will auto-calculate the mass using the shape dimensions and this density value).

    Returns number

    Number, representing the density of this collision shape.

    Default Value

    1000 (kg / m^3)
    
  • get groundEntity(): any
  • Read-only. If the character is supported, this will tell the ground entity.

    Returns any

    Entity, representing the ground.

    Default Value

    null
    
  • get groundNormal(): Vec3
  • Read-only. If the character is supported, this will tell the ground normal. Otherwise, will be a zero vector.

    Returns Vec3

    Vector with ground normal.

    Default Value

    Vec3(0, 0, 0)
    
  • get groundVelocity(): Vec3
  • Read-only. Tells the ground velocity the character is standing on. If the character is not supported, will be a zero vector.

    Returns Vec3

    Ground linear velocity

    Default Value

    Vec3(0, 0, 0)
    
  • get group(): number
  • Collision group bit of an object layer.

    Two layers can collide if object1.group and object2.mask is non-zero and object2.group and object1.mask is non-zero. The behavior is similar to that of filtering in e.g. Bullet, Rapier.

    Returns number

    Unsigned integer.

    Default Value

    0
    
  • set group(group): void
  • Updates the filtering group bit. Value is ignored, if JoltInitSettings.bitFiltering is not set.

    Parameters

    • group: number

      Unsigned integer.

    Returns void

  • get halfExtent(): Vec3
  • Half extent for a SHAPE_BOX.

    Returns Vec3

    Vec3 with half extent of a box collision shape.

    Default Value

    Vec3(0.5, 0.5, 0.5) (m per axis)
    
  • get halfHeight(): number
  • Half-height of radius based shapes.

    Note: Only used by SHAPE_CAPSULE and SHAPE_CYLINDER.

    Returns number

    Number, representing half of the total height of the collision shape.

    Default Value

    0.5 (m)
    
  • get hfActiveEdgeCosThresholdAngle(): number
  • Cosine of the threshold angle. If the angle between the two triangles in HeightField is bigger than this, the edge is active. note that a concave edge is always inactive. Setting this value too small can cause ghost collisions with edges. Setting it too big can cause depenetration artifacts (objects not depenetrating quickly). Valid ranges are between cos(0 degrees) and cos(90 degrees).

    Returns number

    Number, representing radians of the threshold angle.

    Default Value

    0.996195 (cos(5 degrees))
    
  • get hfBitsPerSample(): number
  • How many bits per sample to use to compress the HeightField. Can be in the range [1, 8]. Note that each sample is compressed relative to the min/max value of its block of hfBlockSize * hfBlockSize pixels so the effective precision is higher. Also note that increasing hfBlockSize saves more memory, than reducing the amount of bits per sample.

    Returns number

    Number, representing amount of compression bits.

    Default Value

    8
    
  • get hfBlockSize(): number
  • The HeightField is divided in blocks of hfBlockSize * hfBlockSize * 2 triangles and the acceleration structure culls blocks only, bigger block sizes reduce memory consumption, but also reduce query performance. Sensible values are [2, 8]. Does not need to be a power of 2. Note that at run-time Jolt performs one more grid subdivision, so the effective block size is half of what is provided here.

    Returns number

    Number, representing a block size.

    Default Value

    2
    
  • get hfOffset(): Vec3
  • Offsets the position of the HeightField, which is a surface defined by:

    hfOffset + hfScale * (x, hfHeightSamples[y * hfSampleCount + x], y)
    

    where x and y are integers in the range x and y e [0, hfSampleCount - 1].

    Returns Vec3

    Vec3 with position offset.

    Default Value

    Vec3(0, 0, 0) (m per axis)
    
  • get hitReductionCosMaxAngle(): number
  • The maximum angle between two hits contact normals that are allowed to be merged during hit reduction. Set to -1 to turn off.

    Returns number

    Cosine of an angle.

    Default Value

    ~cos(2.5) (radians)
    
  • set hitReductionCosMaxAngle(angle): void
  • Parameters

    • angle: number

      Max angle.

    Returns void

  • get index(): number
  • Unique body index. This can change during entity lifecycle, e.g. every time entity is enabled, a new index is assigned and a new body is created. The index is used to map entity to body. Index can be re-used by another component if this component is disabled or destroyed (destroying related body as a result).

    Returns number

    Integer number, representing the unique body index.

    Default Value

    -1
    
  • get isCompoundChild(): boolean
  • Specifies if the component describes a child of a compound shape.

    Returns boolean

    Boolean, telling if this component describes a child shape of a compound shape.

    Default Value

    false
    
  • get isSlopeTooSteep(): boolean
  • Read-only. True, if the ground the character is standing on is too steep to walk on.

    Returns boolean

    Boolean, telling if the ground is to steep.

    Default Value

    false
    
  • get isSupported(): boolean
  • Read-only. True, if the character is supported by normal or steep ground.

    Returns boolean

    Boolean, telling if the character is supported.

    Default Value

    false
    
  • get linearVelocity(): Vec3
  • Character linear velocity. Must be set by user. Backend will use it to calculate next position of the character.

    Returns Vec3

    Vec3 with linear velocity.

    Default Value

    Vec3(0, 0, 0)
    
  • set linearVelocity(vel): void
  • Sets the linear velocity of the character.

    Parameters

    • vel: Vec3

      Linear velocity vector to set the character to.

    Returns void

  • get mask(): number
  • Collision mask bit of an object layer.

    Two layers can collide if object1.group and object2.mask is non-zero and object2.group and object1.mask is non-zero. The behavior is similar to that of filtering in e.g. Bullet, Rapier.

    Returns number

    Unsigned integer.

    Default Value

    0
    
  • set mask(mask): void
  • Updates the filtering mask bit. Value is ignored, if JoltInitSettings.bitFiltering is not set.

    Parameters

    • mask: number

      Unsigned integer.

    Returns void

  • get massOffset(): Vec3
  • A center of mass offset in local space of the body. Does not move the shape.

    Returns Vec3

    Vec3 with center of mass offset.

    Default Value

    Vec3(0, 0, 0) (m per axis)
    
  • get maxCollisionIterations(): number
  • Max amount of collision loops. The more loops, the higher the collision precision, the more expensive is the calculation.

    Returns number

    Amount of collision loops.

    Default Value

    5
    
  • get maxConstraintIterations(): number
  • How often constraint solver tries to step. The higher the number, the higher the precision, the more expensive it is to calculate.

    Returns number

    Amount of constraint solving steps.

    Default Value

    15
    
  • get maxSlopeAngle(): number
  • Maximum angle of slope that character can still walk on.

    Returns number

    Slope angle.

    Default Value

    45 * math.DEG_TO_RAD (radians)
    
  • get minTimeRemaining(): number
  • Early out condition: If this much time is left to simulate we are done.

    Returns number

    Remaining time to simulate.

    Default Value

    0.0001 (seconds)
    
  • get pairedEntity(): any
  • An entity with a kinematic or dynamic body, that will be paired with this character. A virtual character doesn't exist in the physics world. Pairing an entity gives it a physical world presence (allow raycasts and collisions detection vs character).

    Returns any

    A paired entity.

    Default Value

    null
    
  • set pairedEntity(entity): void
  • Pairs an Entity with a body component to a character.

    Parameters

    • entity: any

      An entity to pair with the character.

    Returns void

  • get penetrationRecoverySpeed(): number
  • This value governs how fast a penetration will be resolved:

    • 0: nothing is resolved
    • 1: everything is resolved in one update

    Returns number

    Number of updates.

    Default Value

    1
    
  • set penetrationRecoverySpeed(factor): void
  • Parameters

    • factor: number

      Recovery speed factor.

    Returns void

  • get predictiveContactDistance(): number
  • How far to scan outside of the shape for predictive contacts. A value of 0 will most likely cause the character to get stuck as it cannot properly calculate a sliding direction anymore. A value that's too high will cause ghost collisions.

    Returns number

    Predictive contact distance.

    Default Value

    0.1 (meters)
    
  • get radius(): number
  • Radius for radius based shapes, like SHAPE_CAPSULE, SHAPE_SPHERE, etc.

    Returns number

    Number, specifying the shape radius.

    Default Value

    0.5 (m)
    
  • get renderAsset(): null | number
  • This field contains the render asset ID, when a render asset is used for collision mesh or a convex hull.

    Returns null | number

    Asset or its ID number. Will be null if render asset is not used.

    Default Value

    null
    
  • set renderAsset(asset): void
  • Sets render asset as a collider. Note:

    • shape must be SHAPE_MESH or SHAPE_CONVEX_HULL in order for the render asset to be used.
    • If the render asset has multiple mesh instances, only the mesh from the first mesh instance is used. If you need multiple meshes, consider creating a compound collider.

    Parameters

    • asset: any

      Render asset or its id number.

    Returns void

  • get shape(): number
  • Returns the default collision shape type of the character (the one it was created with).

    Returns number

    A shape type constant number.

    Default Value

    SHAPE_CAPSULE
    
  • get shapePosition(): Vec3
  • Local position offset of the collision shape.

    Returns Vec3

    Vec3 with local position offset.

    Default Value

    Vec3(0, 0, 0) (m per axis)
    
  • get shapeRotation(): Quat
  • Local rotation offset of the collision shape.

    Returns Quat

    Quat with local rotation offset.

    Default Value

    Quat(0, 0, 0, 1) (identity rotation)
    
  • get state(): number
  • Ground state. Following constants available:

    GROUND_STATE_ON_GROUND
    
    GROUND_STATE_ON_STEEP_GROUND
    
    GROUND_STATE_NOT_SUPPORTED
    
    GROUND_STATE_IN_AIR
    

    Returns number

    Number, representing the ground state.

    Default Value

    GROUND_STATE_NOT_SUPPORTED
    
  • get supportingVolume(): Plane
  • A plane, defined in local space relative to the character. Every contact behind this plane can support the character, every contact in front of this plane is treated as only colliding with the player.

    Returns Plane

    Plane that is used to define what surfaces support and what collide with character.

    Default Value

    Plane(Vec3.UP, -1)
    
  • get useEntityScale(): boolean
  • Applies entity scale on the shape. This makes it easier to adjust the size of the collision shape by simply scaling the entity.

    Note: Some shapes do not support non-uniformed scales, like SHAPE_SPHERE. Works best with SHAPE_BOX which you can scale on any axis. Others, like capsule and cone, can't have a different radius on X and Z axis, but allow scaling Y for their height.

    Returns boolean

    Boolean, telling if the entity scale is applied on this collision shape.

    Default Value

    true
    
  • get userData(): null | number
  • User data to be associated with this character.

    Returns null | number

    Number if user data is set. Otherwise null;

    Default Value

    null
    
  • set userData(num): void
  • Sets a number on the character shape.

    Sometimes, it is useful to change a behavior of the character inside the collision callback. The callbacks lose the current scope they are executed in, so you can pass custom numbers as user data and read them from inside the callback.

    Parameters

    • num: number

      Number, to set as user data on the character.

    Returns void

  • get walkStairsCosAngleForwardContact(): number
  • Maximum angle in radians between the ground normal in the horizontal plane and the character forward vector where we're willing to adjust the step forward test towards the contact normal.

    Returns number

    Default Value

    cos(75)
    
  • set walkStairsCosAngleForwardContact(angle): void
  • Parameters

    • angle: number

      Radians.

    Returns void

  • get walkStairsStepDownExtra(): Vec3
  • An additional translation that is added when stepping down at the end. Allows you to step further down than up. Set to zero vector if you don't want this. Should be in the opposite direction of up.

    Returns Vec3

    • Extra translation vector.

    Default Value

    Vec3(0, 0, 0)
    
  • set walkStairsStepDownExtra(vec): void
  • Parameters

    • vec: Vec3

      Extra translation.

    Returns void

  • get walkStairsStepForwardTest(): number
  • When running at a high frequency, stepForward can be very small and it's likely that you hit the side of the stairs on the way down. This could produce a normal that violates the max slope angle. If this happens, we test again using this distance from the up position to see if we find a valid slope.

    Returns number

    Default Value

    0.15 (m)
    
  • set walkStairsStepForwardTest(dist): void
  • Parameters

    • dist: number

      Test distance.

    Returns void

Methods

  • Allows to add a shape to a mutable compound shape.

    Parameters

    • shapeIndex: number

      The index of a shape to add. It can be created by createShape.

    • Optional localPos: any = Vec3.ZERO

      Local position of the shape.

    • Optional localRot: any = Quat.IDENTITY

      Local rotation of the shape.

    • Optional userData: number = 0

      User defined unsigned integer.

    Returns void

  • Allows to modify a child shape of a mutable compound shape.

    Parameters

    • childIndex: number

      The child shape index. Children indices are zero based and have no gaps.

    • Optional localPos: any = Vec3.ZERO

      Local position of the shape.

    • Optional localRot: any = Quat.IDENTITY

      Local rotation of the shape.

    • Optional shapeIndex: number = -1

      The index of a shape to add. It can be created by createShape.

    Returns void

  • Allows to remove a child shape from a mutable compound shape. The children are indexed in order they were added. Indices are zero based and have no gaps. If you remove a child, then the next child takes its index.

    For example, if you remove child under index 0, then all children shift there indices, so that the child with index 1, becomes a child with index 0, etc.

    Parameters

    • childIndex: number

      The index of a child shape to remove.

    Returns void

  • Allows to change the shape of the character collider.

    Parameters

    • shapeIndex: number

      The shape index to switch to. It can be created by createShape. Use negative number to reset to original shape.

    • callback: CharSetShapeCallback

      Callback function that will accept a boolean, telling if the shape change was successful.

    Returns void

  • Instant position and rotation change.

    Parameters

    • pos: Vec3

      Character position.

    • Optional rot: any = Quat.IDENTITY

      Character rotation.

    Returns void