PhysicsServer3D
A server interface for low-level 3D physics access.
PhysicsServer3D.swift:26class PhysicsServer3D
PhysicsServer3D is the server responsible for all 3D physics. It can directly create and manipulate all physics objects:
A space is a self-contained world for a physics simulation. It contains bodies, areas, and joints. Its state can be queried for collision and intersection information, and several parameters of the simulation can be modified.
A shape is a geometric shape such as a sphere, a box, a cylinder, or a polygon. It can be used for collision detection by adding it to a body/area, possibly with an extra transformation relative to the body/area’s origin. Bodies/areas can have multiple (transformed) shapes added to them, and a single shape can be added to bodies/areas multiple times with different local transformations.
A body is a physical object which can be in static, kinematic, or rigid mode. Its state (such as position and velocity) can be queried and updated. A force integration callback can be set to customize the body’s physics.
An area is a region in space which can be used to detect bodies and areas entering and exiting it. A body monitoring callback can be set to report entering/exiting body shapes, and similarly an area monitoring callback can be set. Gravity and damping can be overridden within the area by setting area parameters.
A joint is a constraint, either between two bodies or on one body relative to a point. Parameters such as the joint bias and the rest length of a spring joint can be adjusted.
Physics objects in PhysicsServer3D
may be created and manipulated independently; they do not have to be tied to nodes in the scene tree.
Superclasses
class Object
Base class for all other classes in the engine.
Citizens in SwiftGodot
Conformances
protocol CustomStringConvertible
A type with a customized textual representation.
protocol Equatable
A type that can be compared for value equality.
protocol Hashable
A type that can be hashed into a
Hasher
to produce an integer hash value.protocol Identifiable<ID>
A class of types whose instances hold the value of an entity with stable identity.
protocol VariantRepresentable
Types that conform to VariantRepresentable can be stored directly in
Variant
with no conversion. These include all of the Variant types from Godot (for exampleGString
,Rect
,Plane
), Godot objects (those that subclass SwiftGodot.Object) as well as the built-in Swift types UInt8, Int64 and Double.protocol VariantStorable
Types that conform to VariantStorable can be stored in a Variant and can be extracted back out of a Variant.
Types
enum AreaBodyStatus
enum AreaParameter
enum AreaSpaceOverrideMode
enum BodyAxis
enum BodyDampMode
enum BodyMode
enum BodyParameter
enum BodyState
enum ConeTwistJointParam
enum G6DOFJointAxisFlag
enum G6DOFJointAxisParam
enum HingeJointFlag
enum HingeJointParam
enum JointType
enum PinJointParam
enum ProcessInfo
enum ShapeType
enum SliderJointParam
enum SpaceParameter
Type members
static func areaAddShape(area: RID, shape: RID, transform: Transform3D, disabled: Bool
) Adds a shape to the area, along with a transform matrix. Shapes are usually referenced by their index, so you should track which shape has a given index.
static func areaAttachObjectInstanceId(area: RID, id: UInt
) Assigns the area to a descendant of
Object
, so it can exist in the node tree.static func areaClearShapes(area: RID
) Removes all shapes from an area. It does not delete the shapes, so they can be reassigned later.
static func areaCreate(
) -> RID Creates an
Area3D
.static func areaGetCollisionLayer(area: RID
) -> UInt32 Returns the physics layer or layers an area belongs to.
static func areaGetCollisionMask(area: RID
) -> UInt32 Returns the physics layer or layers an area can contact with.
static func areaGetObjectInstanceId(area: RID
) -> UInt Gets the instance ID of the object the area is assigned to.
static func areaGetParam(area: RID, param: PhysicsServer3D.AreaParameter
) -> Variant Returns an area parameter value. A list of available parameters is on the
AreaParameter
constants.static func areaGetShape(area: RID, shapeIdx: Int32
) -> RID Returns the
RID
of the nth shape of an area.static func areaGetShapeCount(area: RID
) -> Int32 Returns the number of shapes assigned to an area.
static func areaGetShapeTransform(area: RID, shapeIdx: Int32
) -> Transform3D Returns the transform matrix of a shape within an area.
static func areaGetSpace(area: RID
) -> RID Returns the space assigned to the area.
static func areaGetTransform(area: RID
) -> Transform3D Returns the transform matrix for an area.
static func areaRemoveShape(area: RID, shapeIdx: Int32
) Removes a shape from an area. It does not delete the shape, so it can be reassigned later.
static func areaSetAreaMonitorCallback(area: RID, callback: Callable
) Sets the area’s area monitor callback. This callback will be called when any other (shape of an) area enters or exits (a shape of) the given area, and must take the following five parameters:
static func areaSetCollisionLayer(area: RID, layer: UInt32
) Assigns the area to one or many physics layers.
static func areaSetCollisionMask(area: RID, mask: UInt32
) Sets which physics layers the area will monitor.
static func areaSetMonitorCallback(area: RID, callback: Callable
) Sets the area’s body monitor callback. This callback will be called when any other (shape of a) body enters or exits (a shape of) the given area, and must take the following five parameters:
static func areaSetMonitorable(area: RID, monitorable: Bool
) static func areaSetParam(area: RID, param: PhysicsServer3D.AreaParameter, value: Variant
) Sets the value for an area parameter. A list of available parameters is on the
AreaParameter
constants.static func areaSetRayPickable(area: RID, enable: Bool
) Sets object pickable with rays.
static func areaSetShape(area: RID, shapeIdx: Int32, shape: RID
) Substitutes a given area shape by another. The old shape is selected by its index, the new one by its
RID
.static func areaSetShapeDisabled(area: RID, shapeIdx: Int32, disabled: Bool
) static func areaSetShapeTransform(area: RID, shapeIdx: Int32, transform: Transform3D
) Sets the transform matrix for an area shape.
static func areaSetSpace(area: RID, space: RID
) Assigns a space to the area.
static func areaSetTransform(area: RID, transform: Transform3D
) Sets the transform matrix for an area.
static func bodyAddCollisionException(body: RID, exceptedBody: RID
) Adds a body to the list of bodies exempt from collisions.
static func bodyAddConstantCentralForce(body: RID, force: Vector3
) Adds a constant directional force without affecting rotation that keeps being applied over time until cleared with
body_set_constant_force(body, Vector3(0, 0, 0))
.static func bodyAddConstantForce(body: RID, force: Vector3, position: Vector3
) Adds a constant positioned force to the body that keeps being applied over time until cleared with
body_set_constant_force(body, Vector3(0, 0, 0))
.static func bodyAddConstantTorque(body: RID, torque: Vector3
) Adds a constant rotational force without affecting position that keeps being applied over time until cleared with
body_set_constant_torque(body, Vector3(0, 0, 0))
.static func bodyAddShape(body: RID, shape: RID, transform: Transform3D, disabled: Bool
) Adds a shape to the body, along with a transform matrix. Shapes are usually referenced by their index, so you should track which shape has a given index.
static func bodyApplyCentralForce(body: RID, force: Vector3
) Applies a directional force without affecting rotation. A force is time dependent and meant to be applied every physics update.
static func bodyApplyCentralImpulse(body: RID, impulse: Vector3
) Applies a directional impulse without affecting rotation.
static func bodyApplyForce(body: RID, force: Vector3, position: Vector3
) Applies a positioned force to the body. A force is time dependent and meant to be applied every physics update.
static func bodyApplyImpulse(body: RID, impulse: Vector3, position: Vector3
) Applies a positioned impulse to the body.
static func bodyApplyTorque(body: RID, torque: Vector3
) Applies a rotational force without affecting position. A force is time dependent and meant to be applied every physics update.
static func bodyApplyTorqueImpulse(body: RID, impulse: Vector3
) Applies a rotational impulse to the body without affecting the position.
static func bodyAttachObjectInstanceId(body: RID, id: UInt
) Assigns the area to a descendant of
Object
, so it can exist in the node tree.static func bodyClearShapes(body: RID
) Removes all shapes from a body.
static func bodyCreate(
) -> RID static func bodyGetCollisionLayer(body: RID
) -> UInt32 Returns the physics layer or layers a body belongs to.
static func bodyGetCollisionMask(body: RID
) -> UInt32 Returns the physics layer or layers a body can collide with.
static func bodyGetCollisionPriority(body: RID
) -> Double Returns the body’s collision priority.
static func bodyGetConstantForce(body: RID
) -> Vector3 Returns the body’s total constant positional forces applied during each physics update.
static func bodyGetConstantTorque(body: RID
) -> Vector3 Returns the body’s total constant rotational forces applied during each physics update.
static func bodyGetDirectState(body: RID
) -> PhysicsDirectBodyState3D? Returns the
PhysicsDirectBodyState3D
of the body. Returnsnull
if the body is destroyed or removed from the physics space.static func bodyGetMaxContactsReported(body: RID
) -> Int32 Returns the maximum contacts that can be reported. See
bodySetMaxContactsReported(body:amount:)
.static func bodyGetMode(body: RID
) -> PhysicsServer3D.BodyMode Returns the body mode.
static func bodyGetObjectInstanceId(body: RID
) -> UInt Gets the instance ID of the object the area is assigned to.
static func bodyGetParam(body: RID, param: PhysicsServer3D.BodyParameter
) -> Variant Returns the value of a body parameter. A list of available parameters is on the
BodyParameter
constants.static func bodyGetShape(body: RID, shapeIdx: Int32
) -> RID Returns the
RID
of the nth shape of a body.static func bodyGetShapeCount(body: RID
) -> Int32 Returns the number of shapes assigned to a body.
static func bodyGetShapeTransform(body: RID, shapeIdx: Int32
) -> Transform3D Returns the transform matrix of a body shape.
static func bodyGetSpace(body: RID
) -> RID Returns the
RID
of the space assigned to a body.static func bodyGetState(body: RID, state: PhysicsServer3D.BodyState
) -> Variant Returns a body state.
static func bodyIsAxisLocked(body: RID, axis: PhysicsServer3D.BodyAxis
) -> Bool static func bodyIsContinuousCollisionDetectionEnabled(body: RID
) -> Bool If
true
, the continuous collision detection mode is enabled.static func bodyIsOmittingForceIntegration(body: RID
) -> Bool Returns whether a body uses a callback function to calculate its own physics (see
bodySetForceIntegrationCallback(body:callable:userdata:)
).static func bodyRemoveCollisionException(body: RID, exceptedBody: RID
) Removes a body from the list of bodies exempt from collisions.
static func bodyRemoveShape(body: RID, shapeIdx: Int32
) Removes a shape from a body. The shape is not deleted, so it can be reused afterwards.
static func bodyResetMassProperties(body: RID
) Restores the default inertia and center of mass based on shapes to cancel any custom values previously set using
bodySetParam(body:param:value:)
.static func bodySetAxisLock(body: RID, axis: PhysicsServer3D.BodyAxis, lock: Bool
) static func bodySetAxisVelocity(body: RID, axisVelocity: Vector3
) Sets an axis velocity. The velocity in the given vector axis will be set as the given vector length. This is useful for jumping behavior.
static func bodySetCollisionLayer(body: RID, layer: UInt32
) Sets the physics layer or layers a body belongs to.
static func bodySetCollisionMask(body: RID, mask: UInt32
) Sets the physics layer or layers a body can collide with.
static func bodySetCollisionPriority(body: RID, priority: Double
) Sets the body’s collision priority.
static func bodySetConstantForce(body: RID, force: Vector3
) Sets the body’s total constant positional forces applied during each physics update.
static func bodySetConstantTorque(body: RID, torque: Vector3
) Sets the body’s total constant rotational forces applied during each physics update.
static func bodySetEnableContinuousCollisionDetection(body: RID, enable: Bool
) If
true
, the continuous collision detection mode is enabled.static func bodySetForceIntegrationCallback(body: RID, callable: Callable, userdata: Variant
) Sets the function used to calculate physics for an object, if that object allows it (see
bodySetOmitForceIntegration(body:enable:)
). The force integration function takes 2 arguments:static func bodySetMaxContactsReported(body: RID, amount: Int32
) Sets the maximum contacts to report. Bodies can keep a log of the contacts with other bodies. This is enabled by setting the maximum number of contacts reported to a number greater than 0.
static func bodySetMode(body: RID, mode: PhysicsServer3D.BodyMode
) Sets the body mode, from one of the
BodyMode
constants.static func bodySetOmitForceIntegration(body: RID, enable: Bool
) Sets whether a body uses a callback function to calculate its own physics (see
bodySetForceIntegrationCallback(body:callable:userdata:)
).static func bodySetParam(body: RID, param: PhysicsServer3D.BodyParameter, value: Variant
) Sets a body parameter. A list of available parameters is on the
BodyParameter
constants.static func bodySetRayPickable(body: RID, enable: Bool
) Sets the body pickable with rays if
enable
is set.static func bodySetShape(body: RID, shapeIdx: Int32, shape: RID
) Substitutes a given body shape by another. The old shape is selected by its index, the new one by its
RID
.static func bodySetShapeDisabled(body: RID, shapeIdx: Int32, disabled: Bool
) static func bodySetShapeTransform(body: RID, shapeIdx: Int32, transform: Transform3D
) Sets the transform matrix for a body shape.
static func bodySetSpace(body: RID, space: RID
) Assigns a space to the body (see
spaceCreate
).static func bodySetState(body: RID, state: PhysicsServer3D.BodyState, value: Variant
) Sets a body state (see
BodyState
constants).static func bodyTestMotion(body: RID, parameters: PhysicsTestMotionParameters3D?, result: PhysicsTestMotionResult3D?
) -> Bool Returns
true
if a collision would result from moving along a motion vector from a given point in space.PhysicsTestMotionParameters3D
is passed to set motion parameters.PhysicsTestMotionResult3D
can be passed to return additional information.static func boxShapeCreate(
) -> RID static func capsuleShapeCreate(
) -> RID static func concavePolygonShapeCreate(
) -> RID static func coneTwistJointGetParam(joint: RID, param: PhysicsServer3D.ConeTwistJointParam
) -> Double Gets a cone_twist_joint parameter (see
ConeTwistJointParam
constants).static func coneTwistJointSetParam(joint: RID, param: PhysicsServer3D.ConeTwistJointParam, value: Double
) Sets a cone_twist_joint parameter (see
ConeTwistJointParam
constants).static func convexPolygonShapeCreate(
) -> RID static func customShapeCreate(
) -> RID static func cylinderShapeCreate(
) -> RID static func freeRid(RID
) Destroys any of the objects created by PhysicsServer3D. If the
RID
passed is not one of the objects that can be created by PhysicsServer3D, an error will be sent to the console.static func generic6dofJointGetFlag(joint: RID, axis: Vector3.Axis, flag: PhysicsServer3D.G6DOFJointAxisFlag
) -> Bool Gets a generic_6_DOF_joint flag (see
G6DOFJointAxisFlag
constants).static func generic6dofJointGetParam(joint: RID, axis: Vector3.Axis, param: PhysicsServer3D.G6DOFJointAxisParam
) -> Double Gets a generic_6_DOF_joint parameter (see
G6DOFJointAxisParam
constants).static func generic6dofJointSetFlag(joint: RID, axis: Vector3.Axis, flag: PhysicsServer3D.G6DOFJointAxisFlag, enable: Bool
) Sets a generic_6_DOF_joint flag (see
G6DOFJointAxisFlag
constants).static func generic6dofJointSetParam(joint: RID, axis: Vector3.Axis, param: PhysicsServer3D.G6DOFJointAxisParam, value: Double
) Sets a generic_6_DOF_joint parameter (see
G6DOFJointAxisParam
constants).static func getProcessInfo(PhysicsServer3D.ProcessInfo
) -> Int32 Returns information about the current state of the 3D physics engine. See
ProcessInfo
for a list of available states.static func heightmapShapeCreate(
) -> RID static func hingeJointGetFlag(joint: RID, flag: PhysicsServer3D.HingeJointFlag
) -> Bool Gets a hinge_joint flag (see
HingeJointFlag
constants).static func hingeJointGetParam(joint: RID, param: PhysicsServer3D.HingeJointParam
) -> Double Gets a hinge_joint parameter (see
HingeJointParam
).static func hingeJointSetFlag(joint: RID, flag: PhysicsServer3D.HingeJointFlag, enabled: Bool
) Sets a hinge_joint flag (see
HingeJointFlag
constants).static func hingeJointSetParam(joint: RID, param: PhysicsServer3D.HingeJointParam, value: Double
) Sets a hinge_joint parameter (see
HingeJointParam
constants).static func jointClear(joint: RID
) static func jointCreate(
) -> RID static func jointDisableCollisionsBetweenBodies(joint: RID, disable: Bool
) Sets whether the bodies attached to the
Joint3D
will collide with each other.static func jointGetSolverPriority(joint: RID
) -> Int32 Gets the priority value of the Joint3D.
static func jointGetType(joint: RID
) -> PhysicsServer3D.JointType Returns the type of the Joint3D.
static func jointIsDisabledCollisionsBetweenBodies(joint: RID
) -> Bool Returns whether the bodies attached to the
Joint3D
will collide with each other.static func jointMakeConeTwist(joint: RID, bodyA: RID, localRefA: Transform3D, bodyB: RID, localRefB: Transform3D
) static func jointMakeGeneric6dof(joint: RID, bodyA: RID, localRefA: Transform3D, bodyB: RID, localRefB: Transform3D
) static func jointMakeHinge(joint: RID, bodyA: RID, hingeA: Transform3D, bodyB: RID, hingeB: Transform3D
) static func jointMakePin(joint: RID, bodyA: RID, localA: Vector3, bodyB: RID, localB: Vector3
) static func jointMakeSlider(joint: RID, bodyA: RID, localRefA: Transform3D, bodyB: RID, localRefB: Transform3D
) static func jointSetSolverPriority(joint: RID, priority: Int32
) Sets the priority value of the Joint3D.
static func pinJointGetLocalA(joint: RID
) -> Vector3 Returns position of the joint in the local space of body a of the joint.
static func pinJointGetLocalB(joint: RID
) -> Vector3 Returns position of the joint in the local space of body b of the joint.
static func pinJointGetParam(joint: RID, param: PhysicsServer3D.PinJointParam
) -> Double Gets a pin_joint parameter (see
PinJointParam
constants).static func pinJointSetLocalA(joint: RID, localA: Vector3
) Sets position of the joint in the local space of body a of the joint.
static func pinJointSetLocalB(joint: RID, localB: Vector3
) Sets position of the joint in the local space of body b of the joint.
static func pinJointSetParam(joint: RID, param: PhysicsServer3D.PinJointParam, value: Double
) Sets a pin_joint parameter (see
PinJointParam
constants).static func separationRayShapeCreate(
) -> RID static func setActive(Bool
) Activates or deactivates the 3D physics engine.
static func shapeGetData(shape: RID
) -> Variant Returns the shape data.
static func shapeGetType(shape: RID
) -> PhysicsServer3D.ShapeType Returns the type of shape (see
ShapeType
constants).static func shapeSetData(shape: RID, data: Variant
) Sets the shape data that defines its shape and size. The data to be passed depends on the kind of shape created
shapeGetType(shape:)
.static func sliderJointGetParam(joint: RID, param: PhysicsServer3D.SliderJointParam
) -> Double Gets a slider_joint parameter (see
SliderJointParam
constants).static func sliderJointSetParam(joint: RID, param: PhysicsServer3D.SliderJointParam, value: Double
) Gets a slider_joint parameter (see
SliderJointParam
constants).static func softBodyGetBounds(body: RID
) -> AABB static func spaceCreate(
) -> RID Creates a space. A space is a collection of parameters for the physics engine that can be assigned to an area or a body. It can be assigned to an area with
areaSetSpace(area:space:)
, or to a body withbodySetSpace(body:space:)
.static func spaceGetDirectState(space: RID
) -> PhysicsDirectSpaceState3D? Returns the state of a space, a
PhysicsDirectSpaceState3D
. This object can be used to make collision/intersection queries.static func spaceGetParam(space: RID, param: PhysicsServer3D.SpaceParameter
) -> Double Returns the value of a space parameter.
static func spaceIsActive(space: RID
) -> Bool Returns whether the space is active.
static func spaceSetActive(space: RID, active: Bool
) Marks a space as active. It will not have an effect, unless it is assigned to an area or body.
static func spaceSetParam(space: RID, param: PhysicsServer3D.SpaceParameter, value: Double
) Sets the value for a space parameter. A list of available parameters is on the
SpaceParameter
constants.static func sphereShapeCreate(
) -> RID static func worldBoundaryShapeCreate(
) -> RID class var godotClassName: StringName
Subclasses
class PhysicsServer3DExtension
Provides virtual methods that can be overridden to create custom
PhysicsServer3D
implementations.