Documentation
¶
Overview ¶
Package RigidBody2D provides methods for working with RigidBody2D object instances.
Index ¶
- type Advanced
- type Any
- type CCDMode
- type CenterOfMassMode
- type DampMode
- type FreezeMode
- type Implementation
- type Instance
- func (self Instance) AddConstantCentralForce(force Vector2.XY)
- func (self Instance) AddConstantForce(force Vector2.XY)
- func (self Instance) AddConstantTorque(torque Float.X)
- func (self Instance) AngularDamp() Float.X
- func (self Instance) AngularDampMode() gdclass.RigidBody2DDampMode
- func (self Instance) AngularVelocity() Float.X
- func (self Instance) ApplyCentralForce(force Vector2.XY)
- func (self Instance) ApplyCentralImpulse()
- func (self Instance) ApplyForce(force Vector2.XY)
- func (self Instance) ApplyImpulse(impulse Vector2.XY)
- func (self Instance) ApplyTorque(torque Float.X)
- func (self Instance) ApplyTorqueImpulse(torque Float.X)
- func (self Instance) AsCanvasItem() CanvasItem.Instance
- func (self Instance) AsCollisionObject2D() CollisionObject2D.Instance
- func (self Instance) AsNode() Node.Instance
- func (self Instance) AsNode2D() Node2D.Instance
- func (self Instance) AsObject() [1]gd.Object
- func (self Instance) AsPhysicsBody2D() PhysicsBody2D.Instance
- func (self Instance) AsRigidBody2D() Instance
- func (self Instance) CanSleep() bool
- func (self Instance) CenterOfMass() Vector2.XY
- func (self Instance) CenterOfMassMode() gdclass.RigidBody2DCenterOfMassMode
- func (self Instance) ConstantForce() Vector2.XY
- func (self Instance) ConstantTorque() Float.X
- func (self Instance) ContactMonitor() bool
- func (self Instance) ContinuousCd() gdclass.RigidBody2DCCDMode
- func (self Instance) CustomIntegrator() bool
- func (self Instance) Freeze() bool
- func (self Instance) FreezeMode() gdclass.RigidBody2DFreezeMode
- func (self Instance) GetCollidingBodies() [][1]gdclass.Node2D
- func (self Instance) GetContactCount() int
- func (self Instance) GravityScale() Float.X
- func (self Instance) Inertia() Float.X
- func (self Instance) LinearDamp() Float.X
- func (self Instance) LinearDampMode() gdclass.RigidBody2DDampMode
- func (self Instance) LinearVelocity() Vector2.XY
- func (self Instance) LockRotation() bool
- func (self Instance) Mass() Float.X
- func (self Instance) MaxContactsReported() int
- func (self Instance) OnBodyEntered(cb func(body [1]gdclass.Node))
- func (self Instance) OnBodyExited(cb func(body [1]gdclass.Node))
- func (self Instance) OnBodyShapeEntered(cb func(body_rid RID.Any, body [1]gdclass.Node, body_shape_index int, ...))
- func (self Instance) OnBodyShapeExited(cb func(body_rid RID.Any, body [1]gdclass.Node, body_shape_index int, ...))
- func (self Instance) OnSleepingStateChanged(cb func())
- func (self Instance) PhysicsMaterialOverride() [1]gdclass.PhysicsMaterial
- func (self Instance) SetAngularDamp(value Float.X)
- func (self Instance) SetAngularDampMode(value gdclass.RigidBody2DDampMode)
- func (self Instance) SetAngularVelocity(value Float.X)
- func (self Instance) SetAxisVelocity(axis_velocity Vector2.XY)
- func (self Instance) SetCanSleep(value bool)
- func (self Instance) SetCenterOfMass(value Vector2.XY)
- func (self Instance) SetCenterOfMassMode(value gdclass.RigidBody2DCenterOfMassMode)
- func (self Instance) SetConstantForce(value Vector2.XY)
- func (self Instance) SetConstantTorque(value Float.X)
- func (self Instance) SetContactMonitor(value bool)
- func (self Instance) SetContinuousCd(value gdclass.RigidBody2DCCDMode)
- func (self Instance) SetCustomIntegrator(value bool)
- func (self Instance) SetFreeze(value bool)
- func (self Instance) SetFreezeMode(value gdclass.RigidBody2DFreezeMode)
- func (self Instance) SetGravityScale(value Float.X)
- func (self Instance) SetInertia(value Float.X)
- func (self Instance) SetLinearDamp(value Float.X)
- func (self Instance) SetLinearDampMode(value gdclass.RigidBody2DDampMode)
- func (self Instance) SetLinearVelocity(value Vector2.XY)
- func (self Instance) SetLockRotation(value bool)
- func (self Instance) SetMass(value Float.X)
- func (self Instance) SetMaxContactsReported(value int)
- func (self Instance) SetPhysicsMaterialOverride(value [1]gdclass.PhysicsMaterial)
- func (self Instance) SetSleeping(value bool)
- func (self Instance) Sleeping() bool
- func (self *Instance) UnsafePointer() unsafe.Pointer
- 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 CCDMode ¶
type CCDMode = gdclass.RigidBody2DCCDMode //gd:RigidBody2D.CCDMode
const ( /*Continuous collision detection disabled. This is the fastest way to detect body collisions, but can miss small, fast-moving objects.*/ CcdModeDisabled CCDMode = 0 /*Continuous collision detection enabled using raycasting. This is faster than shapecasting but less precise.*/ CcdModeCastRay CCDMode = 1 /*Continuous collision detection enabled using shapecasting. This is the slowest CCD method and the most precise.*/ CcdModeCastShape CCDMode = 2 )
type CenterOfMassMode ¶
type CenterOfMassMode = gdclass.RigidBody2DCenterOfMassMode //gd:RigidBody2D.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 [member center_of_mass]. Defaults to the body's origin position.*/ CenterOfMassModeCustom CenterOfMassMode = 1 )
type DampMode ¶
type DampMode = gdclass.RigidBody2DDampMode //gd:RigidBody2D.DampMode
type FreezeMode ¶
type FreezeMode = gdclass.RigidBody2DFreezeMode //gd:RigidBody2D.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 [constant FREEZE_MODE_STATIC], but collides with other bodies along its path when moved. Useful for a frozen body that needs to be animated.*/ FreezeModeKinematic FreezeMode = 1 )
type Implementation ¶
type Implementation = implementation
Implementation implements Interface with empty methods.
type Instance ¶
type Instance [1]gdclass.RigidBody2D
[RigidBody2D] implements full 2D 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 [member lock_rotation], [member freeze], and [member freeze_mode]. By changing various properties of the object, such as [member 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 override the default physics behavior, you can write a custom force integration function. See [member custom_integrator]. [b]Note:[/b] Changing the 2D transform or [member linear_velocity] of a [RigidBody2D] very often may lead to some unpredictable behaviors. If you need to directly affect the body, prefer [method _integrate_forces] as it allows you to directly access the physics state.
See [Interface] for methods that can be overridden by a [Class] that extends it.
%!(EXTRA string=RigidBody2D)
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 [code]constant_force = Vector2(0, 0)[/code]. This is equivalent to using [method add_constant_force] 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 [code]constant_force = Vector2(0, 0)[/code]. [param 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 [code]constant_torque = 0[/code].
func (Instance) AngularDamp ¶
func (Instance) AngularDampMode ¶
func (self Instance) AngularDampMode() gdclass.RigidBody2DDampMode
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 [method apply_force] at the body's center of mass.
func (Instance) ApplyCentralImpulse ¶
func (self 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 [method apply_impulse] 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. [param 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). [param 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. [b]Note:[/b] [member inertia] is required for this to work. To have [member inertia], an active [CollisionShape2D] must be a child of the node, or you can manually set [member 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). [b]Note:[/b] [member inertia] is required for this to work. To have [member inertia], an active [CollisionShape2D] must be a child of the node, or you can manually set [member inertia].
func (Instance) AsCanvasItem ¶
func (self Instance) AsCanvasItem() CanvasItem.Instance
func (Instance) AsCollisionObject2D ¶
func (self Instance) AsCollisionObject2D() CollisionObject2D.Instance
func (Instance) AsPhysicsBody2D ¶
func (self Instance) AsPhysicsBody2D() PhysicsBody2D.Instance
func (Instance) AsRigidBody2D ¶
func (Instance) CenterOfMass ¶
func (Instance) CenterOfMassMode ¶
func (self Instance) CenterOfMassMode() gdclass.RigidBody2DCenterOfMassMode
func (Instance) ConstantForce ¶
func (Instance) ConstantTorque ¶
func (Instance) ContactMonitor ¶
func (Instance) ContinuousCd ¶
func (self Instance) ContinuousCd() gdclass.RigidBody2DCCDMode
func (Instance) CustomIntegrator ¶
func (Instance) FreezeMode ¶
func (self Instance) FreezeMode() gdclass.RigidBody2DFreezeMode
func (Instance) GetCollidingBodies ¶
Returns a list of the bodies colliding with this one. Requires [member contact_monitor] to be set to [code]true[/code] and [member max_contacts_reported] to be set high enough to detect all the collisions. [b]Note:[/b] 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 [member contact_monitor]). [b]Note:[/b] To retrieve the colliding bodies, use [method get_colliding_bodies].
func (Instance) GravityScale ¶
func (Instance) LinearDamp ¶
func (Instance) LinearDampMode ¶
func (self Instance) LinearDampMode() gdclass.RigidBody2DDampMode
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 (self Instance) OnSleepingStateChanged(cb func())
func (Instance) PhysicsMaterialOverride ¶
func (self Instance) PhysicsMaterialOverride() [1]gdclass.PhysicsMaterial
func (Instance) SetAngularDamp ¶
func (Instance) SetAngularDampMode ¶
func (self Instance) SetAngularDampMode(value gdclass.RigidBody2DDampMode)
func (Instance) SetAngularVelocity ¶
func (Instance) SetAxisVelocity ¶
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.
func (Instance) SetCanSleep ¶
func (Instance) SetCenterOfMass ¶
func (Instance) SetCenterOfMassMode ¶
func (self Instance) SetCenterOfMassMode(value gdclass.RigidBody2DCenterOfMassMode)
func (Instance) SetConstantForce ¶
func (Instance) SetConstantTorque ¶
func (Instance) SetContactMonitor ¶
func (Instance) SetContinuousCd ¶
func (self Instance) SetContinuousCd(value gdclass.RigidBody2DCCDMode)
func (Instance) SetCustomIntegrator ¶
func (Instance) SetFreezeMode ¶
func (self Instance) SetFreezeMode(value gdclass.RigidBody2DFreezeMode)
func (Instance) SetGravityScale ¶
func (Instance) SetInertia ¶
func (Instance) SetLinearDamp ¶
func (Instance) SetLinearDampMode ¶
func (self Instance) SetLinearDampMode(value gdclass.RigidBody2DDampMode)
func (Instance) SetLinearVelocity ¶
func (Instance) SetLockRotation ¶
func (Instance) SetMaxContactsReported ¶
func (Instance) SetPhysicsMaterialOverride ¶
func (self Instance) SetPhysicsMaterialOverride(value [1]gdclass.PhysicsMaterial)
func (Instance) SetSleeping ¶
func (*Instance) UnsafePointer ¶
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 [member custom_integrator] property allows you to disable the standard force integration and do fully custom force integration for a body. IntegrateForces(state [1]gdclass.PhysicsDirectBodyState2D) }