Class CollisionObject3D
- Namespace
- Godot
- Assembly
- GodotSharp.dll
Abstract base class for 3D physics objects. CollisionObject3D can hold any number of Shape3Ds 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.
Warning: With a non-uniform scale, this node will likely not behave as expected. It is advised to keep its scale the same on all axes and adjust its collision shape(s) instead.
public class CollisionObject3D : Node3D, IDisposable
- Inheritance
-
CollisionObject3D
- Implements
- Derived
- Inherited Members
Properties
CollisionLayer
The physics layers this CollisionObject3D is in. Collision objects can exist in one or more of 32 different layers. See also CollisionMask.
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.
public uint CollisionLayer { get; set; }
Property Value
CollisionMask
The physics layers this CollisionObject3D scans. Collision objects can scan one or more of 32 different layers. See also CollisionLayer.
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.
public uint CollisionMask { get; set; }
Property Value
CollisionPriority
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.
public float CollisionPriority { get; set; }
Property Value
DisableMode
Defines the behavior in physics when ProcessMode is set to Disabled. See CollisionObject3D.DisableModeEnum for more details about the different modes.
public CollisionObject3D.DisableModeEnum DisableMode { get; set; }
Property Value
InputCaptureOnDrag
If true
, the CollisionObject3D will continue to receive input events as the mouse is dragged across its shapes.
public bool InputCaptureOnDrag { get; set; }
Property Value
InputRayPickable
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 CollisionLayer bit to be set.
public bool InputRayPickable { get; set; }
Property Value
Methods
CreateShapeOwner(GodotObject)
Creates a new shape owner for the given object. Returns owner_id
of the new owner for future reference.
public uint CreateShapeOwner(GodotObject owner)
Parameters
owner
GodotObject
Returns
GetCollisionLayerValue(int)
Returns whether or not the specified layer of the CollisionLayer is enabled, given a layerNumber
between 1 and 32.
public bool GetCollisionLayerValue(int layerNumber)
Parameters
layerNumber
int
Returns
GetCollisionMaskValue(int)
Returns whether or not the specified layer of the CollisionMask is enabled, given a layerNumber
between 1 and 32.
public bool GetCollisionMaskValue(int layerNumber)
Parameters
layerNumber
int
Returns
GetRid()
Returns the object's Rid.
public Rid GetRid()
Returns
GetShapeOwners()
Returns an Array of owner_id
identifiers. You can use these ids in other methods that take owner_id
as an argument.
public int[] GetShapeOwners()
Returns
- int[]
HasGodotClassMethod(in godot_string_name)
Check if the type contains a method with the given name. This method is used by Godot to check if a method exists before invoking it. Do not call or override this method.
protected override bool HasGodotClassMethod(in godot_string_name method)
Parameters
method
godot_string_nameName of the method to check for.
Returns
HasGodotClassSignal(in godot_string_name)
Check if the type contains a signal with the given name. This method is used by Godot to check if a signal exists before raising it. Do not call or override this method.
protected override bool HasGodotClassSignal(in godot_string_name signal)
Parameters
signal
godot_string_nameName of the signal to check for.
Returns
InvokeGodotClassMethod(in godot_string_name, NativeVariantPtrArgs, out godot_variant)
Invokes the method with the given name, using the given arguments. This method is used by Godot to invoke methods from the engine side. Do not call or override this method.
protected override bool InvokeGodotClassMethod(in godot_string_name method, NativeVariantPtrArgs args, out godot_variant ret)
Parameters
method
godot_string_nameName of the method to invoke.
args
NativeVariantPtrArgsArguments to use with the invoked method.
ret
godot_variantValue returned by the invoked method.
Returns
IsShapeOwnerDisabled(uint)
If true
, the shape owner and its shapes are disabled.
public bool IsShapeOwnerDisabled(uint ownerId)
Parameters
ownerId
uint
Returns
RemoveShapeOwner(uint)
Removes the given shape owner.
public void RemoveShapeOwner(uint ownerId)
Parameters
ownerId
uint
SetCollisionLayerValue(int, bool)
Based on value
, enables or disables the specified layer in the CollisionLayer, given a layerNumber
between 1 and 32.
public void SetCollisionLayerValue(int layerNumber, bool value)
Parameters
SetCollisionMaskValue(int, bool)
Based on value
, enables or disables the specified layer in the CollisionMask, given a layerNumber
between 1 and 32.
public void SetCollisionMaskValue(int layerNumber, bool value)
Parameters
ShapeFindOwner(int)
Returns the owner_id
of the given shape.
public uint ShapeFindOwner(int shapeIndex)
Parameters
shapeIndex
int
Returns
ShapeOwnerAddShape(uint, Shape3D)
Adds a Shape3D to the shape owner.
public void ShapeOwnerAddShape(uint ownerId, Shape3D shape)
Parameters
ShapeOwnerClearShapes(uint)
Removes all shapes from the shape owner.
public void ShapeOwnerClearShapes(uint ownerId)
Parameters
ownerId
uint
ShapeOwnerGetOwner(uint)
Returns the parent object of the given shape owner.
public GodotObject ShapeOwnerGetOwner(uint ownerId)
Parameters
ownerId
uint
Returns
ShapeOwnerGetShape(uint, int)
Returns the Shape3D with the given ID from the given shape owner.
public Shape3D ShapeOwnerGetShape(uint ownerId, int shapeId)
Parameters
Returns
ShapeOwnerGetShapeCount(uint)
Returns the number of shapes the given shape owner contains.
public int ShapeOwnerGetShapeCount(uint ownerId)
Parameters
ownerId
uint
Returns
ShapeOwnerGetShapeIndex(uint, int)
Returns the child index of the Shape3D with the given ID from the given shape owner.
public int ShapeOwnerGetShapeIndex(uint ownerId, int shapeId)
Parameters
Returns
ShapeOwnerGetTransform(uint)
Returns the shape owner's Transform3D.
public Transform3D ShapeOwnerGetTransform(uint ownerId)
Parameters
ownerId
uint
Returns
ShapeOwnerRemoveShape(uint, int)
Removes a shape from the given shape owner.
public void ShapeOwnerRemoveShape(uint ownerId, int shapeId)
Parameters
ShapeOwnerSetDisabled(uint, bool)
If true
, disables the given shape owner.
public void ShapeOwnerSetDisabled(uint ownerId, bool disabled)
Parameters
ShapeOwnerSetTransform(uint, Transform3D)
Sets the Transform3D of the given shape owner.
public void ShapeOwnerSetTransform(uint ownerId, Transform3D transform)
Parameters
ownerId
uinttransform
Transform3D
_InputEvent(Camera3D, InputEvent, Vector3, Vector3, int)
Receives unhandled InputEvents. position
is the location in world space of the mouse pointer on the surface of the shape with index shapeIdx
and normal
is the normal vector of the surface at that point. Connect to the InputEvent signal to easily pick up these events.
Note:
_InputEvent(Camera3D, InputEvent, Vector3, Vector3, int) requires InputRayPickable to be true
and at least one CollisionLayer bit to be set.
public virtual void _InputEvent(Camera3D camera, InputEvent @event, Vector3 position, Vector3 normal, int shapeIdx)
Parameters
camera
Camera3Devent
InputEventposition
Vector3normal
Vector3shapeIdx
int
_MouseEnter()
Called when the mouse pointer enters any of this object's shapes. Requires InputRayPickable to be true
and at least one CollisionLayer bit to be set. Note that moving between different shapes within a single CollisionObject3D won't cause this function to be called.
public virtual void _MouseEnter()
_MouseExit()
Called when the mouse pointer exits all this object's shapes. Requires InputRayPickable to be true
and at least one CollisionLayer bit to be set. Note that moving between different shapes within a single CollisionObject3D won't cause this function to be called.
public virtual void _MouseExit()
Events
InputEvent
Emitted when the object receives an unhandled InputEvent. position
is the location in world space of the mouse pointer on the surface of the shape with index shapeIdx
and normal
is the normal vector of the surface at that point.
public event CollisionObject3D.InputEventEventHandler InputEvent
Event Type
MouseEntered
Emitted when the mouse pointer enters any of this object's shapes. Requires InputRayPickable to be true
and at least one CollisionLayer bit to be set.
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 CollisionObject3D's area is small. This signal may also not be emitted if another CollisionObject3D is overlapping the CollisionObject3D in question.
public event Action MouseEntered
Event Type
MouseExited
Emitted when the mouse pointer exits all this object's shapes. Requires InputRayPickable to be true
and at least one CollisionLayer bit to be set.
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 CollisionObject3D's area is small. This signal may also not be emitted if another CollisionObject3D is overlapping the CollisionObject3D in question.
public event Action MouseExited