PhysicsDirectBodyState2D
Provides direct access to a physics body in the PhysicsServer2D
.
class PhysicsDirectBodyState2D
Provides direct access to a physics body in the PhysicsServer2D
, allowing safe changes to physics properties. This object is passed via the direct state callback of RigidBody2D
, and is intended for changing the direct state of that body. See _integrateForces(state:)
.
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.
Type members
Instance members
var angularVelocity: Double
The body’s rotational velocity in radians per second.
var centerOfMass: Vector2
The body’s center of mass position relative to the body’s center in the global coordinate system.
var centerOfMassLocal: Vector2
The body’s center of mass position in the body’s local coordinate system.
var inverseInertia: Double
The inverse of the inertia of the body.
var inverseMass: Double
The inverse of the mass of the body.
var linearVelocity: Vector2
The body’s linear velocity in pixels per second.
var sleeping: Bool
If
true
, this body is currently sleeping (not active).var step: Double
The timestep (delta) used for the simulation.
var totalAngularDamp: Double
The rate at which the body stops rotating, if there are not any other forces moving it.
var totalGravity: Vector2
The total gravity vector being currently applied to this body.
var totalLinearDamp: Double
The rate at which the body stops moving, if there are not any other forces moving it.
var transform: Transform2D
The body’s transformation matrix.
func addConstantCentralForce(Vector2
) Adds a constant directional force without affecting rotation that keeps being applied over time until cleared with
constant_force = Vector2(0, 0)
.func addConstantForce(Vector2, position: Vector2
) Adds a constant positioned force to the body that keeps being applied over time until cleared with
constant_force = Vector2(0, 0)
.func addConstantTorque(Double
) Adds a constant rotational force without affecting position that keeps being applied over time until cleared with
constant_torque = 0
.func applyCentralForce(Vector2
) Applies a directional force without affecting rotation. A force is time dependent and meant to be applied every physics update.
func applyCentralImpulse(Vector2
) Applies a directional impulse without affecting rotation.
func applyForce(Vector2, position: Vector2
) Applies a positioned force to the body. A force is time dependent and meant to be applied every physics update.
func applyImpulse(Vector2, position: Vector2
) Applies a positioned impulse to the body.
func applyTorque(Double
) Applies a rotational force without affecting position. A force is time dependent and meant to be applied every physics update.
func applyTorqueImpulse(Double
) Applies a rotational impulse to the body without affecting the position.
func getConstantForce(
) -> Vector2 Returns the body’s total constant positional forces applied during each physics update.
func getConstantTorque(
) -> Double Returns the body’s total constant rotational forces applied during each physics update.
func getContactCollider(contactIdx: Int32
) -> RID Returns the collider’s
RID
.func getContactColliderId(contactIdx: Int32
) -> UInt Returns the collider’s object id.
func getContactColliderObject(contactIdx: Int32
) -> Object? Returns the collider object. This depends on how it was created (will return a scene node if such was used to create it).
func getContactColliderPosition(contactIdx: Int32
) -> Vector2 Returns the position of the contact point on the collider in the global coordinate system.
func getContactColliderShape(contactIdx: Int32
) -> Int32 Returns the collider’s shape index.
func getContactColliderVelocityAtPosition(contactIdx: Int32
) -> Vector2 Returns the velocity vector at the collider’s contact point.
func getContactCount(
) -> Int32 Returns the number of contacts this body has with other bodies.
func getContactImpulse(contactIdx: Int32
) -> Vector2 Returns the impulse created by the contact.
func getContactLocalNormal(contactIdx: Int32
) -> Vector2 Returns the local normal at the contact point.
func getContactLocalPosition(contactIdx: Int32
) -> Vector2 Returns the position of the contact point on the body in the global coordinate system.
func getContactLocalShape(contactIdx: Int32
) -> Int32 Returns the local shape index of the collision.
func getContactLocalVelocityAtPosition(contactIdx: Int32
) -> Vector2 Returns the velocity vector at the body’s contact point.
func getSpaceState(
) -> PhysicsDirectSpaceState2D? Returns the current state of the space, useful for queries.
func getVelocityAtLocalPosition(Vector2
) -> Vector2 Returns the body’s velocity at the given relative position, including both translation and rotation.
func integrateForces(
) Calls the built-in force integration code.
func setConstantForce(Vector2
) Sets the body’s total constant positional forces applied during each physics update.
func setConstantTorque(Double
) Sets the body’s total constant rotational forces applied during each physics update.
Subclasses
class PhysicsDirectBodyState2DExtension
Provides virtual methods that can be overridden to create custom
PhysicsDirectBodyState2D
implementations.