Physics Components
    Preparing search index...

    Class BodyComponent

    Body Component description.

    Hierarchy (View Summary)

    Index

    Accessors

    • get allowDynamicOrKinematic(): boolean

      When this body is created as MOTION_TYPE_STATIC, this setting tells Jolt system to create a MotionProperties object internally, so that the object can be switched to kinematic or dynamic. Use false, if you don't intend to switch the type of this body from static. This is a performance optimization.

      Returns boolean

      Allow/Disallow a static body to be switched to kinematic/dynamic.

      false
      
    • get allowedDOFs(): number

      Which degrees of freedom this body has (can be used to limit simulation to 2D). For example, using DOF_TRANSLATION_X restricts a body to move in world space X axis.

      Returns number

      Bit number, representing the degrees of freedom.

      DOF_ALL
      
    • set allowedDOFs(degree: number): void

      Changes the allowed degrees of freedom. You can use a combination of following bits:

      DOF_TRANSLATION_X
      
      DOF_TRANSLATION_Y
      
      DOF_TRANSLATION_Z
      
      DOF_ROTATION_X
      
      DOF_ROTATION_Y
      
      DOF_ROTATION_Z
      
      DOF_ALL
      

      Parameters

      • degree: number

        Constant number, representing a degree of freedom.

      Returns void

      // lock translation to X and Z axis and rotation to Y axis
      entity.body.allowedDOFs = DOF_TRANSLATION_X | DOF_TRANSLATION_Z | DOF_ROTATION_Y;
    • get allowSleeping(): boolean

      Specifies if this body go to sleep or not.

      Returns boolean

      Boolean, telling if a body can go to sleep.

      true
      
    • set allowSleeping(bool: boolean): void

      Specifies, whether a body can go to sleep or not.

      • true: allow sleeping
      • false: do not allow to go sleep

      Parameters

      • bool: boolean

        Boolean, telling if a body may go to sleep

      Returns void

    • get angularDamping(): number

      Tells how quickly a body loses angular velocity.

      Returns number

      Number, representing angular damping.

      0
      
    • set angularDamping(factor: number): void

      Sets angular damping factor. The formula used:

      dw/dt = -factor * w
      

      factor must be between 0 and 1 but is usually close to 0.

      Parameters

      • factor: number

        Factor number.

      Returns void

    • get collisionGroup(): number

      The collision group this body belongs to (determines if two objects can collide). Expensive, so disabled by default. Prefer to use broadphase and object layers instead for filtering.

      Returns number

      returns a number, representing a collision group this body belongs to. If no group is set, returns -1;

      -1 (disabled)
      
    • 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.

      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.

      false
      
    • set debugDraw(bool: boolean): 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

      true
      
    • set debugDrawDepth(bool: boolean): 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.

      1000 (kg / m^3)
      
    • get friction(): number

      Friction of the body.

      Returns number

      Number, representing friction factor.

      0.2
      
    • set friction(friction: number): void

      Sets friction. Dimensionless number, usually between 0 and 1:

      • 0: no friction
      • 1: friction force equals force that presses the two bodies together

      Note: bodies can have negative friction, but the combined friction should never go below zero.

      Parameters

      • friction: number

        Friction scalar.

      Returns void

    • get halfHeight(): number

      Half-height of radius based shapes, e.g. SHAPE_CAPSULE.

      Returns number

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

      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.

      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.

      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.

      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.

      Vec3(0, 0, 0) (m per axis)
      
    • 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.

      -1
      
    • get inertiaMultiplier(): number

      When calculating the inertia the calculated inertia will be multiplied by this value. This factor is ignored when overrideMassProperties is set to OMP_MASS_AND_INERTIA_PROVIDED - you are expected to calculate inertia yourself in that case. Cannot be changed after a body is created.

      Returns number

      Number, representing inertia factor.

      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.

      false
      
    • get isometryUpdate(): number

      Returns a type of transform update, telling if and how the position/rotation of this body is updated.

      Returns number

      • Integer, representing update type.
      ISOMETRY_DEFAULT
      
    • set isometryUpdate(type: number): void

      Changes the isometry update method between rendering frontend and physics backend. This only affects automatic updates of active bodies every frame. Static and sleeping bodies are not updated.

      For example, if you have many kinematic bodies that you rarely change position for, you would want to disable the isometry update so you don't burn CPU cycles every frame, and do it manually by setting the entity position and teleporting the body when needed only.

      • ISOMETRY_DEFAULT: frontend will tell backend where a kinematic body is and backend will will tell frontend where a dynamic body is.
      • ISOMETRY_FRONT_TO_BACK: frontend will tell backend where the body is.
      • ISOMETRY_BACK_TO_FRONT: backend will tell frontend where the body is.
      • ISOMETRY_NONE: no automatic isometry update.

      Parameters

      • type: number

        Integer, representing update type.

      Returns void

      entity.addComponent('body', {
      motionType: MOTION_TYPE_KINEMATIC,
      objectLayer: OBJ_LAYER_MOVING,
      isometryUpdate: ISOMETRY_NONE
      });

      // then on frame update, or when needed, move both - body and entity
      entity.setPosition(newPosition);
      entity.body.teleport(newPosition);
      // or any of the body movement methods, e.g.
      // entity.body.moveKinematic(newPosition, Quat.IDENTITY, time);
    • get isSensor(): boolean

      If this body is a sensor. A sensor will receive collision callbacks, but will not cause any collision responses and can be used as a trigger volume.

      Returns boolean

      Boolean, telling if this body is a sensor.

      false
      
    • set isSensor(bool: boolean): void

      Specifies if the body is a sensor or not.

      • true: changes a body into a sensor
      • false: changes a body into a rigid body

      Parameters

      • bool: boolean

        Boolean, telling if this body is a sensor.

      Returns void

    • get linearDamping(): number

      Specifies how quickly the body loses linear velocity. Uses formula:

      dv/dt = -c * v.
      

      c must be between 0 and 1 but is usually close to 0.

      Returns number

      Number, representing a linear damping factor.

      0
      
    • 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.

      Vec3(0, 0, 0) (m per axis)
      
    • get motionQuality(): number

      Motion quality, or how well it detects collisions when it has a high velocity.

      Returns number

      Constant number, representing the collision detection algorithm for this body.

      MOTION_QUALITY_DISCRETE
      
    • set motionQuality(quality: number): void

      Changes the body motion quality. Following constants available:

      MOTION_QUALITY_DISCRETE
      
      MOTION_QUALITY_LINEAR_CAST
      

      Use linear cast (CCD) for fast moving objects, in other cases prefer discrete one since it is cheaper.

      Parameters

      • quality: number

        Quality constant.

      Returns void

    • get motionType(): number

      Motion type, determines if the object is static, dynamic or kinematic. You can use the following constants:

      MOTION_TYPE_STATIC
      
      MOTION_TYPE_DYNAMIC
      
      MOTION_TYPE_KINEMATIC
      

      Returns number

      Number, representing motion type of this body.

      MOTION_TYPE_STATIC
      
    • set motionType(type: number): void

      Parameters

      • type: number

        Number, representing motion quality constant.

      Returns void

    • get objectLayer(): number

      The collision layer this body belongs to (determines if two objects can collide).

      Returns number

      Number, representing the object layer this body belongs to.

      OBJ_LAYER_NON_MOVING
      
    • set objectLayer(layerNumber: number): void

      Changes the object layer that this body belongs to. Allows cheap filtering. Not used, if JoltInitSettings.bitFiltering is provided during system initialization.

      You can use the following pre-made ones:

      OBJ_LAYER_NON_MOVING
      
      OBJ_LAYER_MOVING
      

      Where:

      • OBJ_LAYER_NON_MOVING = 0
      • OBJ_LAYER_MOVING = 1

      Parameters

      • layerNumber: number

        Layer number.

      Returns void

    • get overrideMassProperties(): number

      Determines how a body mass and inertia is calculated. By default it uses OMP_CALCULATE_MASS_AND_INERTIA, which tells Jolt to auto-calculate those based the collider shape. You can use following constants:

      OMP_CALCULATE_INERTIA
      
      OMP_CALCULATE_MASS_AND_INERTIA
      
      OMP_MASS_AND_INERTIA_PROVIDED
      

      If you select OMP_CALCULATE_INERTIA, you must also specify overrideMass. The inertia will be automatically calculated for you.

      If you select OMP_MASS_AND_INERTIA_PROVIDED, you must also specify overrideMass, overrideInertiaPosition and overrideInertiaRotation.

      Cannot be changed after the body is created.

      Returns number

      Number, representing the mass calculation method constant.

      OMP_CALCULATE_MASS_AND_INERTIA (calculates automatically)
      
    • get radius(): number

      Radius for radius based shapes, like SHAPE_CAPSULE, SHAPE_SPHERE, etc.

      Returns number

      Number, specifying the shape radius.

      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.

      null
      
    • set renderAsset(asset: number | 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: number | Asset

        Render asset or its id number.

      Returns void

    • get restitution(): number

      Restitution of the body.

      Returns number

      Number, representing restitution factor for this body.

    • set restitution(factor: number): void

      Sets body restitution. Dimensionless number, usually between 0 and 1:

      • 0: completely inelastic collision response
      • 1: completely elastic collision response

      Note: bodies can have negative restitution but the combined restitution should never go below zero.

      Parameters

      • factor: number

        Restitution scalar.

      Returns void

    • get shape(): number

      Current shape type.

      Returns number

      Number, representing the shape type.

      SHAPE_BOX
      
    • set shape(shapeNum: number): void

      Changes the shape type. Following constants available:

      SHAPE_EMPTY
      
      SHAPE_PLANE
      
      SHAPE_BOX
      
      SHAPE_CAPSULE
      
      SHAPE_TAPERED_CAPSULE
      
      SHAPE_CYLINDER
      
      SHAPE_TAPERED_CYLINDER
      
      SHAPE_SPHERE
      
      SHAPE_MESH
      
      SHAPE_CONVEX_HULL
      
      SHAPE_HEIGHTFIELD
      
      SHAPE_STATIC_COMPOUND
      
      SHAPE_MUTABLE_COMPOUND
      

      Parameters

      • shapeNum: number

        Shape type number.

      Returns void

    • get shapeRotation(): Quat

      Local rotation offset of the collision shape.

      Returns Quat

      Quat with local rotation offset.

      Quat(0, 0, 0, 1) (identity rotation)
      
    • get subGroup(): number

      The collision sub group this body belongs to (determines if two objects can collide). Expensive, so disabled by default. Prefer to use broadphase and object layers instead for filtering.

      Returns number

      If set, will return a number, representing the sub group this body belongs to. Otherwise, will return -1;

      -1 (disabled)
      
    • 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.

      true
      
    • get useMotionState(): boolean

      A motion state for this body. Not used by static bodies.

      If the physcs fixed timestep is set lower than the client's browser refresh rate, then browser will have multiple frame updates per single physics simulation step. If you enable motion state for this entity, then the position and rotation will be interpolated, otherwise the entity will visually move only after physics completes a step.

      For example, say browser refreshes every 0.1 seconds, and physics step once a second. Without using motion state an entity position will update once every second, when physics update takes place. With motion state enabled, it will update the position/rotation every 0.1 seconds - once a true update (from physics) and 9 times interpolated. This will give a smooth motion of the entity, without having to do expensive physics simulation step every frame.

      Returns boolean

      Boolean, telling if motion state is enabled for this body.

      true
      
    • set useMotionState(bool: boolean): void

      Enables/Disables a motion state for this body.

      Parameters

      • bool: boolean

        Boolean to enable/disable the motion state.

      Returns void

    Methods

    • Adds a force (unit: N) at an offset to this body for the next physics time step. Will reset after the physics completes a step.

      Parameters

      • force: Vec3

        Force to add to body.

      • Optionaloffset: Vec3 = Vec3.ZERO

        Offset from the body center where the force is added.

      • OptionalisOffsetLocal: boolean = false

        Specifies if offset is in world or local space.

      Returns void

    • Same as addForce, but accepts scalars, instead of vectors.

      Parameters

      • forceX: number

        Force scalar value on X axis.

      • forceY: number

        Force scalar value on Y axis.

      • forceZ: number

        Force scalar value on Z axis.

      • OptionaloffsetX: number = 0

        Force scalar offset on X axis.

      • OptionaloffsetY: number = 0

        Force scalar offset on Y axis.

      • OptionaloffsetZ: number = 0

        Force scalar offset on Z axis.

      • OptionalisOffsetLocal: number = false

        Specifies if offset is in world or local space.

      Returns void

    • Adds an impulse to the center of mass of the body (unit: kg m/s).

      Parameters

      • impulse: Vec3

        Impulse to add to body.

      • Optionaloffset: Vec3 = Vec3.ZERO

        Offset from the body center where the impulse is added.

      • OptionalisOffsetLocal: boolean = false

        Specifies if offset is in world or local space.

      Returns void

    • Same as addImpulse, but accepts scalars, instead of vectors.

      Parameters

      • impulseX: number

        Impulse scalar value on X axis.

      • impulseY: number

        Impulse scalar value on Y axis.

      • impulseZ: number

        Impulse scalar value on Z axis.

      • OptionaloffsetX: number = 0

        Impulse scalar offset on X axis.

      • OptionaloffsetY: number = 0

        Impulse scalar offset on Y axis.

      • OptionaloffsetZ: number = 0

        Impulse scalar offset on Z axis.

      • OptionalisOffsetLocal: number = false

        Specifies if offset is in world or local space.

      Returns void

    • 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.

      • OptionallocalPos: Vec3 = Vec3.ZERO

        Local position of the shape.

      • OptionallocalRot: Quat = Quat.IDENTITY

        Local rotation of the shape.

      • OptionaluserData: number = 0

        User defined unsigned integer.

      Returns void

    • Applies an impulse to the body that simulates fluid buoyancy and drag.

      Parameters

      • waterSurfacePosition: Vec3

        Position of the fluid surface in world space.

      • surfaceNormal: Vec3

        Normal of the fluid surface (should point up).

      • buoyancy: number

        The buoyancy factor for the body:

        • = 1: neutral body
        • < 1: sinks
        • > 1: floats
      • linearDrag: number

        Linear drag factor that slows down the body when in the fluid (approx. 0.5).

      • angularDrag: number

        Angular drag factor that slows down rotation when the body is in the fluid (approx. 0.01).

      • fluidVelocity: Vec3

        The average velocity of the fluid (in m/s) in which the body resides.

      Returns void

    • Fire an event, all additional arguments are passed on to the event listener.

      Parameters

      • name: string

        Name of event to fire.

      • Optionalarg1: any

        First argument that is passed to the event handler.

      • Optionalarg2: any

        Second argument that is passed to the event handler.

      • Optionalarg3: any

        Third argument that is passed to the event handler.

      • Optionalarg4: any

        Fourth argument that is passed to the event handler.

      • Optionalarg5: any

        Fifth argument that is passed to the event handler.

      • Optionalarg6: any

        Sixth argument that is passed to the event handler.

      • Optionalarg7: any

        Seventh argument that is passed to the event handler.

      • Optionalarg8: any

        Eighth argument that is passed to the event handler.

      Returns EventHandler

      Self for chaining.

      obj.fire('test', 'This is the message');
      
    • Test if there are any handlers bound to an event name.

      Parameters

      • name: string

        The name of the event to test.

      Returns boolean

      True if the object has handlers bound to the specified event name.

      obj.on('test', () => {}); // bind an event to 'test'
      obj.hasEvent('test'); // returns true
      obj.hasEvent('hello'); // returns false
    • 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.

      • OptionallocalPos: Vec3 = Vec3.ZERO

        Local position of the shape.

      • OptionallocalRot: Quat = Quat.IDENTITY

        Local rotation of the shape.

      • OptionalshapeIndex: number = -1

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

      Returns void

    • Changes the position and rotation of a dynamic body. Unlike teleport, this method doesn't change the position/rotation instantenously, but instead calculates and sets linear and angular velocities for the body, so it can reach the target position and rotation in the specified delta time. If delta time is set to zero, the engine will use the current fixed timestep value.

      Parameters

      • pos: Vec3

        Taret position the body should reach in given dt.

      • rot: Quat

        Target rotation the body should reach in given dt.

      • Optionaldt: number = 0

        Time in which the body should reach target position and rotation (seconds).

      Returns void

    • Detach an event handler from an event. If callback is not provided then all callbacks are unbound from the event, if scope is not provided then all events with the callback will be unbound.

      Parameters

      • Optionalname: string

        Name of the event to unbind.

      • Optionalcallback: HandleEventCallback

        Function to be unbound.

      • Optionalscope: object

        Scope that was used as the this when the event is fired.

      Returns EventHandler

      Self for chaining.

      const handler = () => {};
      obj.on('test', handler);

      obj.off(); // Removes all events
      obj.off('test'); // Removes all events called 'test'
      obj.off('test', handler); // Removes all handler functions, called 'test'
      obj.off('test', handler, this); // Removes all handler functions, called 'test' with scope this
    • Attach an event handler to an event.

      Parameters

      • name: string

        Name of the event to bind the callback to.

      • callback: HandleEventCallback

        Function that is called when event is fired. Note the callback is limited to 8 arguments.

      • Optionalscope: object

        Object to use as 'this' when the event is fired, defaults to current this.

      Returns EventHandle

      Can be used for removing event in the future.

      obj.on('test', (a, b) => {
      console.log(a + b);
      });
      obj.fire('test', 1, 2); // prints 3 to the console
      const evt = obj.on('test', (a, b) => {
      console.log(a + b);
      });
      // some time later
      evt.off();
    • Attach an event handler to an event. This handler will be removed after being fired once.

      Parameters

      • name: string

        Name of the event to bind the callback to.

      • callback: HandleEventCallback

        Function that is called when event is fired. Note the callback is limited to 8 arguments.

      • Optionalscope: object

        Object to use as 'this' when the event is fired, defaults to current this.

      Returns EventHandle

      • can be used for removing event in the future.
      obj.once('test', (a, b) => {
      console.log(a + b);
      });
      obj.fire('test', 1, 2); // prints 3 to the console
      obj.fire('test', 1, 2); // not going to get handled
    • 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

    • Set world space linear velocity of the center of mass, will make sure the value is clamped against the maximum linear velocity.

      Parameters

      • velocity: Vec3

        Angular velocity vector.

      Returns void

    • Sets whether kinematic objects can generate contact points against other kinematic or static objects. Note that turning this on can be CPU intensive as much more collision detection work will be done without any effect on the simulation (kinematic objects are not affected by other kinematic/static objects).

      This can be used to make sensors detect static objects. Note that the sensor must be kinematic and active for it to detect static objects.

      Parameters

      • bool: boolean

        Boolean, telling if we want kinematics contactact non-dynamic bodies.

      Returns void

    • Changes the collision group and sub group this body belongs to. Using collision groups is expensive, so it is disabled by default. Prefer to use broadphase and object layers instead for filtering.

      Parameters

      • collisionGroup: number

        Collision group number. Use -1 to disable.

      • subGroup: number

        Sub group number. Use -1 to disable.

      Returns void

    • Set to indicate that extra effort should be made to try to remove ghost contacts (collisions with internal edges of a mesh). This is more expensive but makes bodies move smoother over a mesh with convex edges.

      Parameters

      • bool: boolean

        State boolean

      Returns void

    • Set world space linear velocity of the center of mass, will make sure the value is clamped against the maximum linear velocity.

      Parameters

      • velocity: Vec3

        Linear velocity vector.

      Returns void

    • Used only when this body is dynamic and colliding. Override for the number of solver position iterations to run, 0 means use the default in settings.numPositionSteps. The number of iterations to use is the max of all contacts and constraints in the island.

      Parameters

      • count: number

        Number of velocity steps.

      Returns void

    • Used only when this body is dynamic and colliding. Override for the number of solver velocity iterations to run, 0 means use the default in settings.numVelocitySteps. The number of iterations to use is the max of all contacts and constraints in the island.

      Parameters

      • count: number

        Number of velocity steps.

      Returns void

    • Allows changing the current shape to a custom one.

      Note: once set, you won't be able to destroy this shape using destroyShape. The shape will be destroyed when either the body gets destroyed, or when you change it to another shape.

      Parameters

      • shapeIndex: number

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

      Returns void

      const customShapeIdx = app.physics.createShape(SHAPE_SPHERE, {
      radius: 2,
      shapePosition: new Vec3(0, 1, 0)
      });
      entity.body.setShape(customShapeIdx);
    • Intantenous placement of a body to a new position/rotation (i.e. teleport). Will ignore any bodies between old and new position.

      Parameters

      • position: Vec3

        World space position where to place the body.

      • Optionalrotation: Quat = Quat.IDENTITY

        World space rotation the body should assume at new position.

      Returns void

    • Same as teleport, but taking scalars, instead of vectors.

      Parameters

      • px: number

        Position scalar value on X axis.

      • py: number

        Position scalar value on Y axis.

      • pz: number

        Position scalar value on Z axis.

      • Optionalrx: number = 0

        Rotation scalar value on X axis.

      • Optionalry: number = 0

        Rotation scalar value on Y axis.

      • Optionalrz: number = 0

        Rotation scalar value on Z axis.

      • Optionalrw: number = 1

        Rotation scalar value on W axis.

      Returns void