Inheritance #
- AudioServer
- CameraServer
- ClassDB
- DisplayServer
- EditorFileSystemDirectory
- EditorInterface
- EditorPaths
- EditorSelection
- EditorUndoRedoManager
- EditorVCSInterface
- Engine
- EngineDebugger
- FramebufferCacheRD
- GDExtensionManager
- Geometry2D
- Geometry3D
- IP
- Input
- InputMap
- JNISingleton
- JSONRPC
- JavaClassWrapper
- JavaScriptBridge
- MainLoop (1)
- Marshalls
- MovieWriter
- NativeMenu
- NavigationMeshGenerator
- NavigationServer2D
- NavigationServer3D
- Node (21)
- OS
- OpenXRExtensionWrapperExtension
- OpenXRInteractionProfileMetadata
- Performance
- PhysicsDirectBodyState2D (1)
- PhysicsDirectBodyState3D (1)
- PhysicsDirectSpaceState2D (1)
- PhysicsDirectSpaceState3D (1)
- PhysicsServer2D (1)
- PhysicsServer2DManager
- PhysicsServer3D (1)
- PhysicsServer3DManager
- PhysicsServer3DRendering
ServerHandler
- ProjectSettings
- RefCounted (121)
- RenderData (2)
- RenderSceneData (2)
- RenderingDevice
- RenderingServer
- ResourceLoader
- ResourceSaver
- ResourceUID
- ScriptLanguage (1)
- ShaderIncludeDB
- TextServerManager
- ThemeDB
- TileData
- Time
- TranslationServer
- TreeItem
- UndoRedo
- UniformSetCacheRD
- WorkerThreadPool
- XRServer
- XRVRS
- AnimationMixer (2)
- AudioStreamPlayer
- CanvasItem (2)
- CanvasLayer (1)
- EditorFileSystem
- EditorPlugin (1)
- EditorResourcePreview
- HTTPRequest
- InstancePlaceholder
- MissingNode
- MultiplayerSpawner
- MultiplayerSynchronizer
- NavigationAgent2D
- NavigationAgent3D
- Node3D (31)
- ResourcePreloader
- ShaderGlobalsOverride
- StatusIndicator
- Timer
- Viewport (2)
- WorldEnvironment
- AnimatedSprite2D
- AudioListener2D
- AudioStreamPlayer2D
- BackBufferCopy
- Bone2D
- CPUParticles2D
- Camera2D
- CanvasGroup
- CanvasModulate
- CollisionObject2D (2)
- CollisionPolygon2D
- CollisionShape2D
- GPUParticles2D
- Joint2D (3)
- Light2D (2)
- LightOccluder2D
- Line2D
- Marker2D
- MeshInstance2D
- MultiMeshInstance2D
- NavigationLink2D
- NavigationObstacle2D
- NavigationRegion2D
- Parallax2D
- ParallaxLayer
- Path2D
- PathFollow2D
- Polygon2D
- RayCast2D
- RemoteTransform2D
- ShapeCast2D
- Skeleton2D
- Sprite2D
- TileMap
- TileMapLayer
- TouchScreenButton
- VisibleOnScreenNotifier2D (1)
Table of contents
-
var collision_layer: int = 1 -
var collision_mask: int = 1 -
var collision_priority: float = 1.0 -
var disable_mode = DISABLE_MODE_REMOVE -
var input_pickable: bool = true -
virtual func _input_event(shape_idx: int) -> void -
virtual func _mouse_enter() -> void -
virtual func _mouse_exit() -> void -
virtual func _mouse_shape_enter(shape_idx: int) -> void -
virtual func _mouse_shape_exit(shape_idx: int) -> void -
func create_shape_owner(owner: Object) -> int -
const func get_collision_layer_value(layer_number: int) -> bool -
const func get_collision_mask_value(layer_number: int) -> bool -
const func get_rid() -> RID -
const func get_shape_owner_one_way_collision_margin(owner_id: int) -> float -
func get_shape_owners() -> PackedInt32Array -
const func is_shape_owner_disabled(owner_id: int) -> bool -
const func is_shape_owner_one_way_collision_enabled(owner_id: int) -> bool -
func remove_shape_owner(owner_id: int) -> void -
func set_collision_layer_value(value: bool) -> void -
func set_collision_mask_value(value: bool) -> void -
const func shape_find_owner(shape_index: int) -> int -
func shape_owner_add_shape(shape: Shape2D) -> void -
func shape_owner_clear_shapes(owner_id: int) -> void -
const func shape_owner_get_owner(owner_id: int) -> Object -
const func shape_owner_get_shape(shape_id: int) -> Shape2D -
const func shape_owner_get_shape_count(owner_id: int) -> int -
const func shape_owner_get_shape_index(shape_id: int) -> int -
const func shape_owner_get_transform(owner_id: int) -> Transform2D -
func shape_owner_remove_shape(shape_id: int) -> void -
func shape_owner_set_disabled(disabled: bool) -> void -
func shape_owner_set_one_way_collision(enable: bool) -> void -
func shape_owner_set_one_way_collision_margin(margin: float) -> void -
func shape_owner_set_transform(transform: Transform2D) -> void -
const DISABLE_MODE_REMOVE = 0 enum DisableMode -
const DISABLE_MODE_MAKE_STATIC = 1 enum DisableMode -
const DISABLE_MODE_KEEP_ACTIVE = 2 enum DisableMode -
enum DisableMode -
signal input_event(shape_idx: int) -
signal mouse_entered() -
signal mouse_exited() -
signal mouse_shape_entered(shape_idx: int) -
signal mouse_shape_exited(shape_idx: int)
CollisionObject2D #
Node2D, Node, core, not_builtin_classes
Abstract base class for 2D physics objects.
Abstract base class for 2D physics objects. CollisionObject2D can hold any number of Shape2Ds for collision. Each shape must be assigned to a shape owner. 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.
Members #
var collision_layer: int = 1#
The physics layers this CollisionObject2D is in. Collision objects can exist in one or more of 32 different layers. See also collision_mask.
Note: Object A can detect a contact with object B only if object B is in any of the layers that object A scans. See Collision layers and masks in the documentation for more information.
var collision_mask: int = 1#
The physics layers this CollisionObject2D scans. Collision objects can scan one or more of 32 different layers. See also collision_layer.
Note: Object A can detect a contact with object B only if object B is in any of the layers that object A scans. See Collision layers and masks in the documentation for more information.
var collision_priority: float = 1.0#
The priority used to solve colliding when occurring penetration. The higher the priority is, the lower the penetration into the object will be. This can for example be used to prevent the player from breaking through the boundaries of a level.
var disable_mode = DISABLE_MODE_REMOVE#
Defines the behavior in physics when Node.process_mode is set to Node.PROCESS_MODE_DISABLED. See DisableMode for more details about the different modes.
var input_pickable: bool = true#
If true, this object is pickable. A pickable object can detect the mouse pointer entering/leaving, and if the mouse is inside it, report input events. Requires at least one collision_layer bit to be set.
Methods #
virtual func _input_event(shape_idx: int) -> void#
Accepts unhandled InputEvents. shape_idx is the child index of the clicked Shape2D. Connect to input_event to easily pick up these events.
Note: _input_event requires input_pickable to be true and at least one collision_layer bit to be set.
virtual func _mouse_enter() -> void#
Called when the mouse pointer enters any of this object's shapes. Requires input_pickable to be true and at least one collision_layer bit to be set. Note that moving between different shapes within a single CollisionObject2D won't cause this function to be called.
virtual func _mouse_exit() -> void#
Called when the mouse pointer exits all this object's shapes. Requires input_pickable to be true and at least one collision_layer bit to be set. Note that moving between different shapes within a single CollisionObject2D won't cause this function to be called.
virtual func _mouse_shape_enter(shape_idx: int) -> void#
Called when the mouse pointer enters any of this object's shapes or moves from one shape to another. shape_idx is the child index of the newly entered Shape2D. Requires input_pickable to be true and at least one collision_layer bit to be called.
virtual func _mouse_shape_exit(shape_idx: int) -> void#
Called when the mouse pointer exits any of this object's shapes. shape_idx is the child index of the exited Shape2D. Requires input_pickable to be true and at least one collision_layer bit to be called.
func create_shape_owner(owner: Object) -> int#
Creates a new shape owner for the given object. Returns owner_id of the new owner for future reference.
const func get_collision_layer_value(layer_number: int) -> bool#
Returns whether or not the specified layer of the collision_layer is enabled, given a layer_number between 1 and 32.
const func get_collision_mask_value(layer_number: int) -> bool#
Returns whether or not the specified layer of the collision_mask is enabled, given a layer_number between 1 and 32.
const func get_shape_owner_one_way_collision_margin(owner_id: int) -> float#
Returns the one_way_collision_margin of the shape owner identified by given owner_id.
func get_shape_owners() -> PackedInt32Array#
Returns an Array of owner_id identifiers. You can use these ids in other methods that take owner_id as an argument.
const func is_shape_owner_disabled(owner_id: int) -> bool#
If true, the shape owner and its shapes are disabled.
const func is_shape_owner_one_way_collision_enabled(owner_id: int) -> bool#
Returns true if collisions for the shape owner originating from this CollisionObject2D will not be reported to collided with CollisionObject2Ds.
func remove_shape_owner(owner_id: int) -> void#
Removes the given shape owner.
func set_collision_layer_value(value: bool) -> void#
Based on value, enables or disables the specified layer in the collision_layer, given a layer_number between 1 and 32.
func set_collision_mask_value(value: bool) -> void#
Based on value, enables or disables the specified layer in the collision_mask, given a layer_number between 1 and 32.
const func shape_find_owner(shape_index: int) -> int#
Returns the owner_id of the given shape.
func shape_owner_clear_shapes(owner_id: int) -> void#
Removes all shapes from the shape owner.
const func shape_owner_get_owner(owner_id: int) -> Object#
Returns the parent object of the given shape owner.
const func shape_owner_get_shape(shape_id: int) -> Shape2D#
Returns the Shape2D with the given ID from the given shape owner.
const func shape_owner_get_shape_count(owner_id: int) -> int#
Returns the number of shapes the given shape owner contains.
const func shape_owner_get_shape_index(shape_id: int) -> int#
Returns the child index of the Shape2D with the given ID from the given shape owner.
const func shape_owner_get_transform(owner_id: int) -> Transform2D#
Returns the shape owner's Transform2D.
func shape_owner_remove_shape(shape_id: int) -> void#
Removes a shape from the given shape owner.
func shape_owner_set_disabled(disabled: bool) -> void#
If true, disables the given shape owner.
func shape_owner_set_one_way_collision(enable: bool) -> void#
If enable is true, collisions for the shape owner originating from this CollisionObject2D will not be reported to collided with CollisionObject2Ds.
func shape_owner_set_one_way_collision_margin(margin: float) -> void#
Sets the one_way_collision_margin of the shape owner identified by given owner_id to margin pixels.
func shape_owner_set_transform(transform: Transform2D) -> void#
Sets the Transform2D of the given shape owner.
Annotations #
Constants #
const DISABLE_MODE_REMOVE = 0 enum DisableMode#
When Node.process_mode is set to 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.
const DISABLE_MODE_MAKE_STATIC = 1 enum DisableMode#
When Node.process_mode is set to 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.
const DISABLE_MODE_KEEP_ACTIVE = 2 enum DisableMode#
When Node.process_mode is set to Node.PROCESS_MODE_DISABLED, do not affect the physics simulation.
Constructors #
Enums #
DisableMode#
enum DisableMode {
DISABLE_MODE_REMOVE = 0,
DISABLE_MODE_MAKE_STATIC = 1,
DISABLE_MODE_KEEP_ACTIVE = 2,
} Operators #
Signals #
signal input_event(shape_idx: int)#
Emitted when an input event occurs. Requires input_pickable to be true and at least one collision_layer bit to be set. See _input_event for details.
signal mouse_entered()#
Emitted when the mouse pointer enters any of this object's shapes. Requires input_pickable to be true and at least one collision_layer bit to be set. Note that moving between different shapes within a single CollisionObject2D won't cause this signal to be emitted.
Note: Due to the lack of continuous collision detection, this signal may not be emitted in the expected order if the mouse moves fast enough and the CollisionObject2D's area is small. This signal may also not be emitted if another CollisionObject2D is overlapping the CollisionObject2D in question.
signal mouse_exited()#
Emitted when the mouse pointer exits all this object's shapes. Requires input_pickable to be true and at least one collision_layer bit to be set. Note that moving between different shapes within a single CollisionObject2D won't cause this signal to be emitted.
Note: Due to the lack of continuous collision detection, this signal may not be emitted in the expected order if the mouse moves fast enough and the CollisionObject2D's area is small. This signal may also not be emitted if another CollisionObject2D is overlapping the CollisionObject2D in question.
signal mouse_shape_entered(shape_idx: int)#
Emitted when the mouse pointer enters any of this object's shapes or moves from one shape to another. shape_idx is the child index of the newly entered Shape2D. Requires input_pickable to be true and at least one collision_layer bit to be set.
signal mouse_shape_exited(shape_idx: int)#
Emitted when the mouse pointer exits any of this object's shapes. shape_idx is the child index of the exited Shape2D. Requires input_pickable to be true and at least one collision_layer bit to be set.