Signal1
Signal support.
RigidBody2D.swift:1805class Signal1
Use the connect(flags:_:)
method to connect to the signal on the container object, and disconnect(_:)
to drop the connection.
You can also await the emitted
property for waiting for a single emission of the signal.
Other members in extension
View members
Hide members
This section is hidden by default because it contains too many (49) members.
Types
enum CCDMode
enum CenterOfMassMode
enum DampMode
enum FreezeMode
class Signal2
Signal support.
class Signal3
Signal support.
class Signal4
Signal support.
Type members
Instance members
var angularDamp: Double
Damps the body’s rotation. By default, the body will use the Default Angular Damp in Project > Project Settings > Physics > 2d or any value override set by an
Area2D
the body is in. Depending onangularDampMode
, you can setangularDamp
to be added to or to replace the body’s damping value.var angularDampMode: RigidBody2D.DampMode
Defines how
angularDamp
is applied. SeeDampMode
for possible values.var angularVelocity: Double
The body’s rotational velocity in radians per second.
var bodyEntered: Signal3
Emitted when a collision with another
PhysicsBody2D
orTileMap
occurs. RequirescontactMonitor
to be set totrue
andmaxContactsReported
to be set high enough to detect all the collisions.TileMap
s are detected if theTileSet
has CollisionShape2D
s.var bodyExited: Signal4
Emitted when the collision with another
PhysicsBody2D
orTileMap
ends. RequirescontactMonitor
to be set totrue
andmaxContactsReported
to be set high enough to detect all the collisions.TileMap
s are detected if theTileSet
has CollisionShape2D
s.var bodyShapeEntered: Signal1
Emitted when one of this RigidBody2D’s
Shape2D
s collides with anotherPhysicsBody2D
orTileMap
’sShape2D
s. RequirescontactMonitor
to be set totrue
andmaxContactsReported
to be set high enough to detect all the collisions.TileMap
s are detected if theTileSet
has CollisionShape2D
s.var bodyShapeExited: Signal2
Emitted when the collision between one of this RigidBody2D’s
Shape2D
s and anotherPhysicsBody2D
orTileMap
’sShape2D
s ends. RequirescontactMonitor
to be set totrue
andmaxContactsReported
to be set high enough to detect all the collisions.TileMap
s are detected if theTileSet
has CollisionShape2D
s.var canSleep: Bool
If
true
, the body can enter sleep mode when there is no movement. Seesleeping
.var centerOfMass: Vector2
The body’s custom center of mass, relative to the body’s origin position, when
centerOfMassMode
is set to .custom. This is the balanced point of the body, where applied forces only cause linear acceleration. Applying forces outside of the center of mass causes angular acceleration.var centerOfMassMode: RigidBody2D.CenterOfMassMode
Defines the way the body’s center of mass is set. See
CenterOfMassMode
for possible values.var constantForce: Vector2
The body’s total constant positional forces applied during each physics update.
var constantTorque: Double
The body’s total constant rotational forces applied during each physics update.
var contactMonitor: Bool
If
true
, the RigidBody2D will emit signals when it collides with another body.var continuousCd: RigidBody2D.CCDMode
Continuous collision detection mode.
var customIntegrator: Bool
If
true
, the standard force integration (like gravity or damping) will be disabled for this body. Other than collision response, the body will only move as determined by the_integrateForces(state:)
method, if that virtual method is overridden.var freeze: Bool
If
true
, the body is frozen. Gravity and forces are not applied anymore.var freezeMode: RigidBody2D.FreezeMode
The body’s freeze mode. Can be used to set the body’s behavior when
freeze
is enabled. SeeFreezeMode
for possible values.var gravityScale: Double
Multiplies the gravity applied to the body. The body’s gravity is calculated from the Default Gravity value in Project > Project Settings > Physics > 2d and/or any additional gravity vector applied by
Area2D
s.var inertia: Double
The body’s moment of inertia. This is like mass, but for rotation: it determines how much torque it takes to rotate the body. The moment of inertia is usually computed automatically from the mass and the shapes, but this property allows you to set a custom value.
var linearDamp: Double
Damps the body’s movement. By default, the body will use the Default Linear Damp in Project > Project Settings > Physics > 2d or any value override set by an
Area2D
the body is in. Depending onlinearDampMode
, you can setlinearDamp
to be added to or to replace the body’s damping value.var linearDampMode: RigidBody2D.DampMode
Defines how
linearDamp
is applied. SeeDampMode
for possible values.var linearVelocity: Vector2
The body’s linear velocity in pixels per second. Can be used sporadically, but don’t set this every frame, because physics may run in another thread and runs at a different granularity. Use
_integrateForces(state:)
as your process loop for precise control of the body state.var lockRotation: Bool
If
true
, the body cannot rotate. Gravity and forces only apply linear movement.var mass: Double
The body’s mass.
var maxContactsReported: Int32
The maximum number of contacts that will be recorded. Requires a value greater than 0 and
contactMonitor
to be set totrue
to start to register contacts. UsegetContactCount
to retrieve the count orgetCollidingBodies
to retrieve bodies that have been collided with.var physicsMaterialOverride: PhysicsMaterial?
The physics material override for the body.
var sleeping: Bool
If
true
, the body will not move and will not calculate forces until woken up by another body through, for example, a collision, or by using theapplyImpulse(_:position:)
orapplyForce(_:position:)
methods.var sleepingStateChanged: SimpleSignal
Emitted when the physics engine changes the body’s sleeping state.
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(torque: Double
) Applies a rotational impulse to the body without affecting the position.
func getCollidingBodies(
) -> ObjectCollection<Node2D> Returns a list of the bodies colliding with this one. Requires
contactMonitor
to be set totrue
andmaxContactsReported
to be set high enough to detect all the collisions.func getContactCount(
) -> Int32 Returns the number of contacts this body has with other bodies. By default, this returns 0 unless bodies are configured to monitor contacts (see
contactMonitor
).func setAxisVelocity(Vector2
) Sets the body’s velocity on the given axis. The velocity in the given vector axis will be set as the given vector length. This is useful for jumping behavior.
Show implementation details (1)
Hide implementation details
func _integrateForces(state: PhysicsDirectBodyState2D?
) Called during physics processing, allowing you to read and safely modify the simulation state for the object. By default, it is called before the standard force integration, but the
customIntegrator
property allows you to disable the standard force integration and do fully custom force integration for a body.
Citizens in SwiftGodot
Instance members
var emitted: Void
You can await this property to wait for the signal to be emitted once
func connect(flags: Object.ConnectFlags, @escaping (_ bodyRid: RID, _ body: Node, _ bodyShapeIndex: Int64, _ localShapeIndex: Int64) -> ()
) -> Object Connects the signal to the specified callback
func disconnect(Object
) Disconnects a signal that was previously connected, the return value from calling
connect(flags:_:)