Class ShapeCast3D
- Namespace
- Godot
- Assembly
- GodotSharp.dll
Shape casting allows to detect collision objects by sweeping its Shape along the cast direction determined by TargetPosition. This is similar to RayCast3D, but it allows for sweeping a region of space, rather than just a straight line. ShapeCast3D can detect multiple collision objects. It is useful for things like wide laser beams or snapping a simple shape to a floor.
Immediate collision overlaps can be done with the TargetPosition set to Vector3(0, 0, 0)
and by calling ForceShapecastUpdate() within the same physics frame. This helps to overcome some limitations of Area3D when used as an instantaneous detection area, as collision information isn't immediately available to it.
Note: Shape casting is more computationally expensive than ray casting.
public class ShapeCast3D : Node3D, IDisposable
- Inheritance
-
ShapeCast3D
- Implements
- Inherited Members
Constructors
ShapeCast3D()
public ShapeCast3D()
Properties
CollideWithAreas
If true
, collisions with Area3Ds will be reported.
public bool CollideWithAreas { get; set; }
Property Value
CollideWithBodies
If true
, collisions with PhysicsBody3Ds will be reported.
public bool CollideWithBodies { get; set; }
Property Value
CollisionMask
The shape's collision mask. Only objects in at least one collision layer enabled in the mask will be detected. See Collision layers and masks in the documentation for more information.
public uint CollisionMask { get; set; }
Property Value
CollisionResult
Returns the complete collision information from the collision sweep. The data returned is the same as in the GetRestInfo(PhysicsShapeQueryParameters3D) method.
public Array CollisionResult { get; }
Property Value
DebugShapeCustomColor
The custom color to use to draw the shape in the editor and at run-time if Visible Collision Shapes is enabled in the Debug menu. This color will be highlighted at run-time if the ShapeCast3D is colliding with something.
If set to Color(0.0, 0.0, 0.0)
(by default), the color set in ProjectSettings.debug/shapes/collision/shape_color
is used.
public Color DebugShapeCustomColor { get; set; }
Property Value
Enabled
If true
, collisions will be reported.
public bool Enabled { get; set; }
Property Value
ExcludeParent
If true
, the parent node will be excluded from collision detection.
public bool ExcludeParent { get; set; }
Property Value
Margin
The collision margin for the shape. A larger margin helps detecting collisions more consistently, at the cost of precision.
public float Margin { get; set; }
Property Value
MaxResults
The number of intersections can be limited with this parameter, to reduce the processing time.
public int MaxResults { get; set; }
Property Value
Shape
The Shape3D-derived shape to be used for collision queries.
public Shape3D Shape { get; set; }
Property Value
TargetPosition
The shape's destination point, relative to this node's position
.
public Vector3 TargetPosition { get; set; }
Property Value
Methods
AddException(CollisionObject3D)
Adds a collision exception so the shape does not report collisions with the specified CollisionObject3D node.
public void AddException(CollisionObject3D node)
Parameters
node
CollisionObject3D
AddExceptionRid(Rid)
Adds a collision exception so the shape does not report collisions with the specified Rid.
public void AddExceptionRid(Rid rid)
Parameters
rid
Rid
ClearExceptions()
Removes all collision exceptions for this ShapeCast3D.
public void ClearExceptions()
ForceShapecastUpdate()
Updates the collision information for the shape immediately, without waiting for the next _physics_process
call. Use this method, for example, when the shape or its parent has changed state.
Note:
enabled == true
is not required for this to work.
public void ForceShapecastUpdate()
GetClosestCollisionSafeFraction()
The fraction from the ShapeCast3D's origin to its TargetPosition (between 0 and 1) of how far the shape can move without triggering a collision.
public float GetClosestCollisionSafeFraction()
Returns
GetClosestCollisionUnsafeFraction()
The fraction from the ShapeCast3D's origin to its TargetPosition (between 0 and 1) of how far the shape must move to trigger a collision.
public float GetClosestCollisionUnsafeFraction()
Returns
GetCollider(int)
Returns the collided GodotObject of one of the multiple collisions at index
, or null
if no object is intersecting the shape (i.e. IsColliding() returns false
).
public GodotObject GetCollider(int index)
Parameters
index
int
Returns
GetColliderRid(int)
Returns the Rid of the collided object of one of the multiple collisions at index
.
public Rid GetColliderRid(int index)
Parameters
index
int
Returns
GetColliderShape(int)
Returns the shape ID of the colliding shape of one of the multiple collisions at index
, or 0
if no object is intersecting the shape (i.e. IsColliding() returns false
).
public int GetColliderShape(int index)
Parameters
index
int
Returns
GetCollisionCount()
The number of collisions detected at the point of impact. Use this to iterate over multiple collisions as provided by GetCollider(int), GetColliderShape(int), GetCollisionPoint(int), and GetCollisionNormal(int) methods.
public int GetCollisionCount()
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
GetCollisionNormal(int)
Returns the normal of one of the multiple collisions at index
of the intersecting object.
public Vector3 GetCollisionNormal(int index)
Parameters
index
int
Returns
GetCollisionPoint(int)
Returns the collision point of one of the multiple collisions at index
where the shape intersects the colliding object.
Note: this point is in the global coordinate system.
public Vector3 GetCollisionPoint(int index)
Parameters
index
int
Returns
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
IsColliding()
Returns whether any object is intersecting with the shape's vector (considering the vector length).
public bool IsColliding()
Returns
RemoveException(CollisionObject3D)
Removes a collision exception so the shape does report collisions with the specified CollisionObject3D node.
public void RemoveException(CollisionObject3D node)
Parameters
node
CollisionObject3D
RemoveExceptionRid(Rid)
Removes a collision exception so the shape does report collisions with the specified Rid.
public void RemoveExceptionRid(Rid rid)
Parameters
rid
Rid
ResourceChanged(Resource)
Obsoleted. Use Changed instead.
[Obsolete("This method is deprecated.")]
public void ResourceChanged(Resource resource)
Parameters
resource
Resource
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)