RigidBody2D

package
v0.0.0-...-c909628 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 13, 2025 License: MIT Imports: 25 Imported by: 0

Documentation

Overview

Package RigidBody2D provides methods for working with RigidBody2D object instances.

Index

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 Any

type Any interface {
	gd.IsClass
	AsRigidBody2D() Instance
}

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
const (
	/*In this mode, the body's damping value is added to any value set in areas or the default value.*/
	DampModeCombine DampMode = 0
	/*In this mode, the body's damping value replaces any value set in areas or the default value.*/
	DampModeReplace DampMode = 1
)

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 New

func New() Instance

func (Instance) AddConstantCentralForce

func (self Instance) AddConstantCentralForce(force Vector2.XY)

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

func (self Instance) AddConstantForce(force Vector2.XY)

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

func (self Instance) AddConstantTorque(torque Float.X)

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 (self Instance) AngularDamp() Float.X

func (Instance) AngularDampMode

func (self Instance) AngularDampMode() gdclass.RigidBody2DDampMode

func (Instance) AngularVelocity

func (self Instance) AngularVelocity() Float.X

func (Instance) ApplyCentralForce

func (self Instance) ApplyCentralForce(force Vector2.XY)

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

func (self Instance) ApplyForce(force Vector2.XY)

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

func (self Instance) ApplyImpulse(impulse Vector2.XY)

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

func (self Instance) ApplyTorque(torque Float.X)

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

func (self Instance) ApplyTorqueImpulse(torque Float.X)

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) AsNode

func (self Instance) AsNode() Node.Instance

func (Instance) AsNode2D

func (self Instance) AsNode2D() Node2D.Instance

func (Instance) AsObject

func (self Instance) AsObject() [1]gd.Object

func (Instance) AsPhysicsBody2D

func (self Instance) AsPhysicsBody2D() PhysicsBody2D.Instance

func (Instance) AsRigidBody2D

func (self Instance) AsRigidBody2D() Instance

func (Instance) CanSleep

func (self Instance) CanSleep() bool

func (Instance) CenterOfMass

func (self Instance) CenterOfMass() Vector2.XY

func (Instance) CenterOfMassMode

func (self Instance) CenterOfMassMode() gdclass.RigidBody2DCenterOfMassMode

func (Instance) ConstantForce

func (self Instance) ConstantForce() Vector2.XY

func (Instance) ConstantTorque

func (self Instance) ConstantTorque() Float.X

func (Instance) ContactMonitor

func (self Instance) ContactMonitor() bool

func (Instance) ContinuousCd

func (self Instance) ContinuousCd() gdclass.RigidBody2DCCDMode

func (Instance) CustomIntegrator

func (self Instance) CustomIntegrator() bool

func (Instance) Freeze

func (self Instance) Freeze() bool

func (Instance) FreezeMode

func (self Instance) FreezeMode() gdclass.RigidBody2DFreezeMode

func (Instance) GetCollidingBodies

func (self Instance) GetCollidingBodies() [][1]gdclass.Node2D

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

func (self Instance) GetContactCount() int

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 (self Instance) GravityScale() Float.X

func (Instance) Inertia

func (self Instance) Inertia() Float.X

func (Instance) LinearDamp

func (self Instance) LinearDamp() Float.X

func (Instance) LinearDampMode

func (self Instance) LinearDampMode() gdclass.RigidBody2DDampMode

func (Instance) LinearVelocity

func (self Instance) LinearVelocity() Vector2.XY

func (Instance) LockRotation

func (self Instance) LockRotation() bool

func (Instance) Mass

func (self Instance) Mass() Float.X

func (Instance) MaxContactsReported

func (self Instance) MaxContactsReported() int

func (Instance) OnBodyEntered

func (self Instance) OnBodyEntered(cb func(body [1]gdclass.Node))

func (Instance) OnBodyExited

func (self Instance) OnBodyExited(cb func(body [1]gdclass.Node))

func (Instance) OnBodyShapeEntered

func (self Instance) OnBodyShapeEntered(cb func(body_rid RID.Any, body [1]gdclass.Node, body_shape_index int, local_shape_index int))

func (Instance) OnBodyShapeExited

func (self Instance) OnBodyShapeExited(cb func(body_rid RID.Any, body [1]gdclass.Node, body_shape_index int, local_shape_index int))

func (Instance) OnSleepingStateChanged

func (self Instance) OnSleepingStateChanged(cb func())

func (Instance) PhysicsMaterialOverride

func (self Instance) PhysicsMaterialOverride() [1]gdclass.PhysicsMaterial

func (Instance) SetAngularDamp

func (self Instance) SetAngularDamp(value Float.X)

func (Instance) SetAngularDampMode

func (self Instance) SetAngularDampMode(value gdclass.RigidBody2DDampMode)

func (Instance) SetAngularVelocity

func (self Instance) SetAngularVelocity(value Float.X)

func (Instance) SetAxisVelocity

func (self Instance) SetAxisVelocity(axis_velocity Vector2.XY)

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 (self Instance) SetCanSleep(value bool)

func (Instance) SetCenterOfMass

func (self Instance) SetCenterOfMass(value Vector2.XY)

func (Instance) SetCenterOfMassMode

func (self Instance) SetCenterOfMassMode(value gdclass.RigidBody2DCenterOfMassMode)

func (Instance) SetConstantForce

func (self Instance) SetConstantForce(value Vector2.XY)

func (Instance) SetConstantTorque

func (self Instance) SetConstantTorque(value Float.X)

func (Instance) SetContactMonitor

func (self Instance) SetContactMonitor(value bool)

func (Instance) SetContinuousCd

func (self Instance) SetContinuousCd(value gdclass.RigidBody2DCCDMode)

func (Instance) SetCustomIntegrator

func (self Instance) SetCustomIntegrator(value bool)

func (Instance) SetFreeze

func (self Instance) SetFreeze(value bool)

func (Instance) SetFreezeMode

func (self Instance) SetFreezeMode(value gdclass.RigidBody2DFreezeMode)

func (Instance) SetGravityScale

func (self Instance) SetGravityScale(value Float.X)

func (Instance) SetInertia

func (self Instance) SetInertia(value Float.X)

func (Instance) SetLinearDamp

func (self Instance) SetLinearDamp(value Float.X)

func (Instance) SetLinearDampMode

func (self Instance) SetLinearDampMode(value gdclass.RigidBody2DDampMode)

func (Instance) SetLinearVelocity

func (self Instance) SetLinearVelocity(value Vector2.XY)

func (Instance) SetLockRotation

func (self Instance) SetLockRotation(value bool)

func (Instance) SetMass

func (self Instance) SetMass(value Float.X)

func (Instance) SetMaxContactsReported

func (self Instance) SetMaxContactsReported(value int)

func (Instance) SetPhysicsMaterialOverride

func (self Instance) SetPhysicsMaterialOverride(value [1]gdclass.PhysicsMaterial)

func (Instance) SetSleeping

func (self Instance) SetSleeping(value bool)

func (Instance) Sleeping

func (self Instance) Sleeping() bool

func (*Instance) UnsafePointer

func (self *Instance) UnsafePointer() unsafe.Pointer

func (Instance) Virtual

func (self Instance) Virtual(name string) reflect.Value

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)
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL