Documentation
¶
Overview ¶
graphics.gd/classdb/RigidBody3D implements full 3D physics. It cannot be controlled directly, instead, you must apply forces to it (gravity, impulses, etc.), and the physics simulation will calculate the resulting movement, rotation, react to collisions, and affect other physics bodies in its path.
The body's behavior can be adjusted via Instance.LockRotation, Instance.Freeze, and Instance.FreezeMode. By changing various properties of the object, such as Instance.Mass, you can control how the physics simulation acts on it.
A rigid body will always maintain its shape and size, even when forces are applied to it. It is useful for objects that can be interacted with in an environment, such as a tree that can be knocked over or a stack of crates that can be pushed around.
If you need to directly affect the body, prefer [Interface.IntegrateForces] as it allows you to directly access the physics state.
If you need to override the default physics behavior, you can write a custom force integration function. See Instance.CustomIntegrator.
Note: Changing the 3D transform or Instance.LinearVelocity of a graphics.gd/classdb/RigidBody3D very often may lead to some unpredictable behaviors. This also happens when a graphics.gd/classdb/RigidBody3D is the descendant of a constantly moving node, like another graphics.gd/classdb/RigidBody3D, as that will cause its global transform to be set whenever its ancestor moves.
Index ¶
- type Advanced
- type Any
- type CenterOfMassMode
- type DampMode
- type Expanded
- type Extension
- func (self *Extension[T]) AsCollisionObject3D() CollisionObject3D.Instance
- func (self *Extension[T]) AsNode() Node.Instance
- func (self *Extension[T]) AsNode3D() Node3D.Instance
- func (self *Extension[T]) AsObject() [1]gd.Object
- func (self *Extension[T]) AsPhysicsBody3D() PhysicsBody3D.Instance
- func (self *Extension[T]) AsRigidBody3D() Instance
- type FreezeMode
- type ID
- type Implementation
- type Instance
- func (self Instance) AddConstantCentralForce(force Vector3.XYZ)
- func (self Instance) AddConstantForce(force Vector3.XYZ)
- func (self Instance) AddConstantTorque(torque Vector3.XYZ)
- func (self Instance) AngularDamp() Float.X
- func (self Instance) AngularDampMode() DampMode
- func (self Instance) AngularVelocity() Vector3.XYZ
- func (self Instance) ApplyCentralForce(force Vector3.XYZ)
- func (self Instance) ApplyCentralImpulse(impulse Vector3.XYZ)
- func (self Instance) ApplyForce(force Vector3.XYZ)
- func (self Instance) ApplyImpulse(impulse Vector3.XYZ)
- func (self Instance) ApplyTorque(torque Vector3.XYZ)
- func (self Instance) ApplyTorqueImpulse(impulse Vector3.XYZ)
- func (self Instance) AsCollisionObject3D() CollisionObject3D.Instance
- func (self Instance) AsNode() Node.Instance
- func (self Instance) AsNode3D() Node3D.Instance
- func (self Instance) AsObject() [1]gd.Object
- func (self Instance) AsPhysicsBody3D() PhysicsBody3D.Instance
- func (self Instance) AsRigidBody3D() Instance
- func (self Instance) CanSleep() bool
- func (self Instance) CenterOfMass() Vector3.XYZ
- func (self Instance) CenterOfMassMode() CenterOfMassMode
- func (self Instance) ConstantForce() Vector3.XYZ
- func (self Instance) ConstantTorque() Vector3.XYZ
- func (self Instance) ContactMonitor() bool
- func (self Instance) ContinuousCd() bool
- func (self Instance) CustomIntegrator() bool
- func (self Instance) Freeze() bool
- func (self Instance) FreezeMode() FreezeMode
- func (self Instance) GetCollidingBodies() []Node3D.Instance
- func (self Instance) GetContactCount() int
- func (self Instance) GetInverseInertiaTensor() Basis.XYZ
- func (self Instance) GravityScale() Float.X
- func (self Instance) ID() ID
- func (self Instance) Inertia() Vector3.XYZ
- func (self Instance) LinearDamp() Float.X
- func (self Instance) LinearDampMode() DampMode
- func (self Instance) LinearVelocity() Vector3.XYZ
- func (self Instance) LockRotation() bool
- func (self Instance) Mass() Float.X
- func (self Instance) MaxContactsReported() int
- func (self Instance) OnBodyEntered(cb func(body Node.Instance), flags ...Signal.Flags)
- func (self Instance) OnBodyExited(cb func(body Node.Instance), flags ...Signal.Flags)
- func (self Instance) OnBodyShapeEntered(cb func(body_rid RID.Any, body Node.Instance, body_shape_index int, ...), ...)
- func (self Instance) OnBodyShapeExited(cb func(body_rid RID.Any, body Node.Instance, body_shape_index int, ...), ...)
- func (self Instance) OnSleepingStateChanged(cb func(), flags ...Signal.Flags)
- func (self Instance) PhysicsMaterialOverride() PhysicsMaterial.Instance
- func (self Instance) SetAngularDamp(value Float.X)
- func (self Instance) SetAngularDampMode(value DampMode)
- func (self Instance) SetAngularVelocity(value Vector3.XYZ)
- func (self Instance) SetAxisVelocity(axis_velocity Vector3.XYZ)
- func (self Instance) SetCanSleep(value bool)
- func (self Instance) SetCenterOfMass(value Vector3.XYZ)
- func (self Instance) SetCenterOfMassMode(value CenterOfMassMode)
- func (self Instance) SetConstantForce(value Vector3.XYZ)
- func (self Instance) SetConstantTorque(value Vector3.XYZ)
- func (self Instance) SetContactMonitor(value bool)
- func (self Instance) SetContinuousCd(value bool)
- func (self Instance) SetCustomIntegrator(value bool)
- func (self Instance) SetFreeze(value bool)
- func (self Instance) SetFreezeMode(value FreezeMode)
- func (self Instance) SetGravityScale(value Float.X)
- func (self Instance) SetInertia(value Vector3.XYZ)
- func (self Instance) SetLinearDamp(value Float.X)
- func (self Instance) SetLinearDampMode(value DampMode)
- func (self Instance) SetLinearVelocity(value Vector3.XYZ)
- func (self Instance) SetLockRotation(value bool)
- func (self Instance) SetMass(value Float.X)
- func (self Instance) SetMaxContactsReported(value int)
- func (self *Instance) SetObject(obj [1]gd.Object) bool
- func (self Instance) SetPhysicsMaterialOverride(value PhysicsMaterial.Instance)
- func (self Instance) SetSleeping(value bool)
- func (self Instance) Sleeping() bool
- func (self Instance) Virtual(name string) reflect.Value
- type Interface
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Advanced ¶
type Advanced = class
Advanced exposes a 1:1 low-level instance of the class, undocumented, for those who know what they are doing.
type CenterOfMassMode ¶
type CenterOfMassMode int //gd:RigidBody3D.CenterOfMassMode
const ( // In this mode, the body's center of mass is calculated automatically based on its shapes. This assumes that the shapes' origins are also their center of mass. CenterOfMassModeAuto CenterOfMassMode = 0 // In this mode, the body's center of mass is set through [Instance.CenterOfMass]. Defaults to the body's origin position. CenterOfMassModeCustom CenterOfMassMode = 1 )
type Expanded ¶
type Expanded [1]gdclass.RigidBody3D
func (Expanded) AddConstantForce ¶
Adds a constant positioned force to the body that keeps being applied over time until cleared with constant_force = Vector3(0, 0, 0).
'position' is the offset from the body origin in global coordinates.
func (Expanded) ApplyForce ¶
Applies a positioned force to the body. A force is time dependent and meant to be applied every physics update.
'position' is the offset from the body origin in global coordinates.
func (Expanded) ApplyImpulse ¶
Applies a positioned impulse to the body.
An impulse is time-independent! Applying an impulse every frame would result in a framerate-dependent force. For this reason, it should only be used when simulating one-time impacts (use the "_force" functions otherwise).
'position' is the offset from the body origin in global coordinates.
type Extension ¶
Extension can be embedded in a new struct to create an extension of this class. T should be the type that is embedding this [Extension]See Interface for methods that can be overridden by T.
func (*Extension[T]) AsCollisionObject3D ¶
func (self *Extension[T]) AsCollisionObject3D() CollisionObject3D.Instance
func (*Extension[T]) AsPhysicsBody3D ¶
func (self *Extension[T]) AsPhysicsBody3D() PhysicsBody3D.Instance
func (*Extension[T]) AsRigidBody3D ¶
type FreezeMode ¶
type FreezeMode int //gd:RigidBody3D.FreezeMode
const ( // Static body freeze mode (default). The body is not affected by gravity and forces. It can be only moved by user code and doesn't collide with other bodies along its path. FreezeModeStatic FreezeMode = 0 // Kinematic body freeze mode. Similar to [FreezeModeStatic], but collides with other bodies along its path when moved. Useful for a frozen body that needs to be animated. FreezeModeKinematic FreezeMode = 1 )
type ID ¶
ID is a typed object ID (reference) to an instance of this class, use it to store references to objects with unknown lifetimes, as an ID will not panic on use if the underlying object has been destroyed.
type Implementation ¶
type Implementation = implementation
Implementation implements Interface with empty methods.
type Instance ¶
type Instance [1]gdclass.RigidBody3D
Instance of the class with convieniently typed arguments and results.
var Nil Instance
Nil is a nil/null instance of the class. Equivalent to the zero value.
func (Instance) AddConstantCentralForce ¶
Adds a constant directional force without affecting rotation that keeps being applied over time until cleared with constant_force = Vector3(0, 0, 0).
This is equivalent to using Instance.AddConstantForce at the body's center of mass.
func (Instance) AddConstantForce ¶
Adds a constant positioned force to the body that keeps being applied over time until cleared with constant_force = Vector3(0, 0, 0).
'position' is the offset from the body origin in global coordinates.
func (Instance) AddConstantTorque ¶
Adds a constant rotational force without affecting position that keeps being applied over time until cleared with constant_torque = Vector3(0, 0, 0).
func (Instance) AngularDamp ¶
func (Instance) AngularDampMode ¶
func (Instance) AngularVelocity ¶
func (Instance) ApplyCentralForce ¶
Applies a directional force without affecting rotation. A force is time dependent and meant to be applied every physics update.
This is equivalent to using Instance.ApplyForce at the body's center of mass.
func (Instance) ApplyCentralImpulse ¶
Applies a directional impulse without affecting rotation.
An impulse is time-independent! Applying an impulse every frame would result in a framerate-dependent force. For this reason, it should only be used when simulating one-time impacts (use the "_force" functions otherwise).
This is equivalent to using Instance.ApplyImpulse at the body's center of mass.
func (Instance) ApplyForce ¶
Applies a positioned force to the body. A force is time dependent and meant to be applied every physics update.
'position' is the offset from the body origin in global coordinates.
func (Instance) ApplyImpulse ¶
Applies a positioned impulse to the body.
An impulse is time-independent! Applying an impulse every frame would result in a framerate-dependent force. For this reason, it should only be used when simulating one-time impacts (use the "_force" functions otherwise).
'position' is the offset from the body origin in global coordinates.
func (Instance) ApplyTorque ¶
Applies a rotational force without affecting position. A force is time dependent and meant to be applied every physics update.
Note: Instance.Inertia is required for this to work. To have Instance.Inertia, an active graphics.gd/classdb/CollisionShape3D must be a child of the node, or you can manually set Instance.Inertia.
func (Instance) ApplyTorqueImpulse ¶
Applies a rotational impulse to the body without affecting the position.
An impulse is time-independent! Applying an impulse every frame would result in a framerate-dependent force. For this reason, it should only be used when simulating one-time impacts (use the "_force" functions otherwise).
Note: Instance.Inertia is required for this to work. To have Instance.Inertia, an active graphics.gd/classdb/CollisionShape3D must be a child of the node, or you can manually set Instance.Inertia.
func (Instance) AsCollisionObject3D ¶
func (self Instance) AsCollisionObject3D() CollisionObject3D.Instance
func (Instance) AsPhysicsBody3D ¶
func (self Instance) AsPhysicsBody3D() PhysicsBody3D.Instance
func (Instance) AsRigidBody3D ¶
func (Instance) CenterOfMass ¶
func (Instance) CenterOfMassMode ¶
func (self Instance) CenterOfMassMode() CenterOfMassMode
func (Instance) ConstantForce ¶
func (Instance) ConstantTorque ¶
func (Instance) ContactMonitor ¶
func (Instance) ContinuousCd ¶
func (Instance) CustomIntegrator ¶
func (Instance) FreezeMode ¶
func (self Instance) FreezeMode() FreezeMode
func (Instance) GetCollidingBodies ¶
Returns a list of the bodies colliding with this one. Requires Instance.ContactMonitor to be set to true and Instance.MaxContactsReported to be set high enough to detect all the collisions.
Note: The result of this test is not immediate after moving objects. For performance, list of collisions is updated once per frame and before the physics step. Consider using signals instead.
func (Instance) GetContactCount ¶
Returns the number of contacts this body has with other bodies. By default, this returns 0 unless bodies are configured to monitor contacts (see Instance.ContactMonitor).
Note: To retrieve the colliding bodies, use Instance.GetCollidingBodies.
func (Instance) GetInverseInertiaTensor ¶
Returns the inverse inertia tensor basis. This is used to calculate the angular acceleration resulting from a torque applied to the graphics.gd/classdb/RigidBody3D.
func (Instance) GravityScale ¶
func (Instance) LinearDamp ¶
func (Instance) LinearDampMode ¶
func (Instance) LinearVelocity ¶
func (Instance) LockRotation ¶
func (Instance) MaxContactsReported ¶
func (Instance) OnBodyEntered ¶
func (Instance) OnBodyExited ¶
func (Instance) OnBodyShapeEntered ¶
func (Instance) OnBodyShapeExited ¶
func (Instance) OnSleepingStateChanged ¶
func (Instance) PhysicsMaterialOverride ¶
func (self Instance) PhysicsMaterialOverride() PhysicsMaterial.Instance
func (Instance) SetAngularDamp ¶
func (Instance) SetAngularDampMode ¶
func (Instance) SetAngularVelocity ¶
func (Instance) SetAxisVelocity ¶
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.
func (Instance) SetCanSleep ¶
func (Instance) SetCenterOfMass ¶
func (Instance) SetCenterOfMassMode ¶
func (self Instance) SetCenterOfMassMode(value CenterOfMassMode)
func (Instance) SetConstantForce ¶
func (Instance) SetConstantTorque ¶
func (Instance) SetContactMonitor ¶
func (Instance) SetContinuousCd ¶
func (Instance) SetCustomIntegrator ¶
func (Instance) SetFreezeMode ¶
func (self Instance) SetFreezeMode(value FreezeMode)
func (Instance) SetGravityScale ¶
func (Instance) SetInertia ¶
func (Instance) SetLinearDamp ¶
func (Instance) SetLinearDampMode ¶
func (Instance) SetLinearVelocity ¶
func (Instance) SetLockRotation ¶
func (Instance) SetMaxContactsReported ¶
func (Instance) SetPhysicsMaterialOverride ¶
func (self Instance) SetPhysicsMaterialOverride(value PhysicsMaterial.Instance)
func (Instance) SetSleeping ¶
type Interface ¶
type Interface interface { // 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 [Instance.CustomIntegrator] property allows you to disable the standard force integration and do fully custom force integration for a body. IntegrateForces(state PhysicsDirectBodyState3D.Instance) }