CollisionObject2D

package
v0.0.0-...-ad02d68 Latest Latest
Warning

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

Go to latest
Published: Sep 13, 2025 License: MIT Imports: 29 Imported by: 0

Documentation

Overview

Abstract base class for 2D physics objects. [CollisionObject2D] can hold any number of [Shape2D]s for collision. Each shape must be assigned to a [i]shape owner[/i]. Shape owners are not nodes and do not appear in the editor, but are accessible through code using the shape_owner_* methods. Note: Only collisions between objects within the same canvas ([Viewport] canvas or [CanvasLayer]) are supported. The behavior of collisions between objects in different canvases is undefined.

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
	AsCollisionObject2D() Instance
}

type DisableMode

type DisableMode int //gd:CollisionObject2D.DisableMode
const (
	/*When [member Node.process_mode] is set to [constant Node.PROCESS_MODE_DISABLED], remove from the physics simulation to stop all physics interactions with this [CollisionObject2D].
	  Automatically re-added to the physics simulation when the [Node] is processed again.*/
	DisableModeRemove DisableMode = 0
	/*When [member Node.process_mode] is set to [constant Node.PROCESS_MODE_DISABLED], make the body static. Doesn't affect [Area2D]. [PhysicsBody2D] can't be affected by forces or other bodies while static.
	  Automatically set [PhysicsBody2D] back to its original mode when the [Node] is processed again.*/
	DisableModeMakeStatic DisableMode = 1
	/*When [member Node.process_mode] is set to [constant Node.PROCESS_MODE_DISABLED], do not affect the physics simulation.*/
	DisableModeKeepActive DisableMode = 2
)

type Extension

type Extension[T gdclass.Interface] struct{ gdclass.Extension[T, Instance] }

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

func (*Extension[T]) AsCanvasItem

func (self *Extension[T]) AsCanvasItem() CanvasItem.Instance

func (*Extension[T]) AsCollisionObject2D

func (self *Extension[T]) AsCollisionObject2D() Instance

func (*Extension[T]) AsNode

func (self *Extension[T]) AsNode() Node.Instance

func (*Extension[T]) AsNode2D

func (self *Extension[T]) AsNode2D() Node2D.Instance

func (*Extension[T]) AsObject

func (self *Extension[T]) AsObject() [1]gd.Object

type ID

type ID Object.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.

func (ID) Instance

func (id ID) Instance() (Instance, bool)

type Implementation

type Implementation = implementation

Implementation implements Interface with empty methods.

type Instance

type Instance [1]gdclass.CollisionObject2D

Instance of the class with convieniently typed arguments and results. See Interface for methods that can be overridden by a [Class] that extends it.

var Nil Instance

Nil is a nil/null instance of the class. Equivalent to the zero value.

func New

func New() Instance

func (Instance) AsCanvasItem

func (self Instance) AsCanvasItem() CanvasItem.Instance

func (Instance) AsCollisionObject2D

func (self Instance) AsCollisionObject2D() 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) CollisionLayer

func (self Instance) CollisionLayer() int

func (Instance) CollisionMask

func (self Instance) CollisionMask() int

func (Instance) CollisionPriority

func (self Instance) CollisionPriority() Float.X

func (Instance) CreateShapeOwner

func (self Instance) CreateShapeOwner(owner Object.Instance) int

Creates a new shape owner for the given object. Returns owner_id of the new owner for future reference.

func (Instance) DisableMode

func (self Instance) DisableMode() DisableMode

func (Instance) GetCollisionLayerValue

func (self Instance) GetCollisionLayerValue(layer_number int) bool

Returns whether or not the specified layer of the [member collision_layer] is enabled, given a 'layer_number' between 1 and 32.

func (Instance) GetCollisionMaskValue

func (self Instance) GetCollisionMaskValue(layer_number int) bool

Returns whether or not the specified layer of the [member collision_mask] is enabled, given a 'layer_number' between 1 and 32.

func (Instance) GetRid

func (self Instance) GetRid() RID.Body2D

Returns the object's [RID].

func (Instance) GetShapeOwnerOneWayCollisionMargin

func (self Instance) GetShapeOwnerOneWayCollisionMargin(owner_id int) Float.X

Returns the one_way_collision_margin of the shape owner identified by given 'owner_id'.

func (Instance) GetShapeOwners

func (self Instance) GetShapeOwners() []int32

Returns an [Array] of owner_id identifiers. You can use these ids in other methods that take owner_id as an argument.

func (Instance) ID

func (self Instance) ID() ID

func (Instance) InputPickable

func (self Instance) InputPickable() bool

func (Instance) IsShapeOwnerDisabled

func (self Instance) IsShapeOwnerDisabled(owner_id int) bool

If true, the shape owner and its shapes are disabled.

func (Instance) IsShapeOwnerOneWayCollisionEnabled

func (self Instance) IsShapeOwnerOneWayCollisionEnabled(owner_id int) bool

Returns true if collisions for the shape owner originating from this [CollisionObject2D] will not be reported to collided with [CollisionObject2D]s.

func (Instance) OnInputEvent

func (self Instance) OnInputEvent(cb func(viewport Node.Instance, event InputEvent.Instance, shape_idx int), flags ...Signal.Flags)

func (Instance) OnMouseEntered

func (self Instance) OnMouseEntered(cb func(), flags ...Signal.Flags)

func (Instance) OnMouseExited

func (self Instance) OnMouseExited(cb func(), flags ...Signal.Flags)

func (Instance) OnMouseShapeEntered

func (self Instance) OnMouseShapeEntered(cb func(shape_idx int), flags ...Signal.Flags)

func (Instance) OnMouseShapeExited

func (self Instance) OnMouseShapeExited(cb func(shape_idx int), flags ...Signal.Flags)

func (Instance) RemoveShapeOwner

func (self Instance) RemoveShapeOwner(owner_id int)

Removes the given shape owner.

func (Instance) SetCollisionLayer

func (self Instance) SetCollisionLayer(value int)

func (Instance) SetCollisionLayerValue

func (self Instance) SetCollisionLayerValue(layer_number int, value bool)

Based on 'value', enables or disables the specified layer in the [member collision_layer], given a 'layer_number' between 1 and 32.

func (Instance) SetCollisionMask

func (self Instance) SetCollisionMask(value int)

func (Instance) SetCollisionMaskValue

func (self Instance) SetCollisionMaskValue(layer_number int, value bool)

Based on 'value', enables or disables the specified layer in the [member collision_mask], given a 'layer_number' between 1 and 32.

func (Instance) SetCollisionPriority

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

func (Instance) SetDisableMode

func (self Instance) SetDisableMode(value DisableMode)

func (Instance) SetInputPickable

func (self Instance) SetInputPickable(value bool)

func (*Instance) SetObject

func (self *Instance) SetObject(obj [1]gd.Object) bool

func (Instance) ShapeFindOwner

func (self Instance) ShapeFindOwner(shape_index int) int

Returns the owner_id of the given shape.

func (Instance) ShapeOwnerAddShape

func (self Instance) ShapeOwnerAddShape(owner_id int, shape Shape2D.Instance)

Adds a [Shape2D] to the shape owner.

func (Instance) ShapeOwnerClearShapes

func (self Instance) ShapeOwnerClearShapes(owner_id int)

Removes all shapes from the shape owner.

func (Instance) ShapeOwnerGetOwner

func (self Instance) ShapeOwnerGetOwner(owner_id int) Object.Instance

Returns the parent object of the given shape owner.

func (Instance) ShapeOwnerGetShape

func (self Instance) ShapeOwnerGetShape(owner_id int, shape_id int) Shape2D.Instance

Returns the [Shape2D] with the given ID from the given shape owner.

func (Instance) ShapeOwnerGetShapeCount

func (self Instance) ShapeOwnerGetShapeCount(owner_id int) int

Returns the number of shapes the given shape owner contains.

func (Instance) ShapeOwnerGetShapeIndex

func (self Instance) ShapeOwnerGetShapeIndex(owner_id int, shape_id int) int

Returns the child index of the [Shape2D] with the given ID from the given shape owner.

func (Instance) ShapeOwnerGetTransform

func (self Instance) ShapeOwnerGetTransform(owner_id int) Transform2D.OriginXY

Returns the shape owner's [Transform2D].

func (Instance) ShapeOwnerRemoveShape

func (self Instance) ShapeOwnerRemoveShape(owner_id int, shape_id int)

Removes a shape from the given shape owner.

func (Instance) ShapeOwnerSetDisabled

func (self Instance) ShapeOwnerSetDisabled(owner_id int, disabled bool)

If true, disables the given shape owner.

func (Instance) ShapeOwnerSetOneWayCollision

func (self Instance) ShapeOwnerSetOneWayCollision(owner_id int, enable bool)

If 'enable' is true, collisions for the shape owner originating from this [CollisionObject2D] will not be reported to collided with [CollisionObject2D]s.

func (Instance) ShapeOwnerSetOneWayCollisionMargin

func (self Instance) ShapeOwnerSetOneWayCollisionMargin(owner_id int, margin Float.X)

Sets the one_way_collision_margin of the shape owner identified by given 'owner_id' to 'margin' pixels.

func (Instance) ShapeOwnerSetTransform

func (self Instance) ShapeOwnerSetTransform(owner_id int, transform Transform2D.OriginXY)

Sets the [Transform2D] of the given shape owner.

func (Instance) Virtual

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

type Interface

type Interface interface {
	//Accepts unhandled [InputEvent]s. [param shape_idx] is the child index of the clicked [Shape2D]. Connect to [signal input_event] to easily pick up these events.
	//[b]Note:[/b] [method _input_event] requires [member input_pickable] to be [code]true[/code] and at least one [member collision_layer] bit to be set.
	InputEvent(viewport Viewport.Instance, event InputEvent.Instance, shape_idx int)
	//Called when the mouse pointer enters any of this object's shapes. Requires [member input_pickable] to be [code]true[/code] and at least one [member collision_layer] bit to be set. Note that moving between different shapes within a single [CollisionObject2D] won't cause this function to be called.
	MouseEnter()
	//Called when the mouse pointer exits all this object's shapes. Requires [member input_pickable] to be [code]true[/code] and at least one [member collision_layer] bit to be set. Note that moving between different shapes within a single [CollisionObject2D] won't cause this function to be called.
	MouseExit()
	//Called when the mouse pointer enters any of this object's shapes or moves from one shape to another. [param shape_idx] is the child index of the newly entered [Shape2D]. Requires [member input_pickable] to be [code]true[/code] and at least one [member collision_layer] bit to be called.
	MouseShapeEnter(shape_idx int)
	//Called when the mouse pointer exits any of this object's shapes. [param shape_idx] is the child index of the exited [Shape2D]. Requires [member input_pickable] to be [code]true[/code] and at least one [member collision_layer] bit to be called.
	MouseShapeExit(shape_idx int)
}

Jump to

Keyboard shortcuts

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