ShapeCast3D
A 3D shape that sweeps a region of space to detect CollisionObject3D
s.
class ShapeCast3D
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.
Superclasses
class Node3D
Most basic 3D game object, parent of all 3D-related nodes.
Citizens in SwiftGodot
Conformances
protocol CustomStringConvertible
A type with a customized textual representation.
protocol Equatable
A type that can be compared for value equality.
protocol Hashable
A type that can be hashed into a
Hasher
to produce an integer hash value.protocol Identifiable<ID>
A class of types whose instances hold the value of an entity with stable identity.
protocol VariantRepresentable
Types that conform to VariantRepresentable can be stored directly in
Variant
with no conversion. These include all of the Variant types from Godot (for exampleGString
,Rect
,Plane
), Godot objects (those that subclass SwiftGodot.Object) as well as the built-in Swift types UInt8, Int64 and Double.protocol VariantStorable
Types that conform to VariantStorable can be stored in a Variant and can be extracted back out of a Variant.
Type members
Instance members
var collideWithAreas: Bool
If
true
, collisions withArea3D
s will be reported.var collideWithBodies: Bool
If
true
, collisions withPhysicsBody3D
s will be reported.var collisionMask: UInt32
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.
var debugShapeCustomColor: Color
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.var enabled: Bool
If
true
, collisions will be reported.var excludeParent: Bool
If
true
, the parent node will be excluded from collision detection.var margin: Double
The collision margin for the shape. A larger margin helps detecting collisions more consistently, at the cost of precision.
var maxResults: Int32
The number of intersections can be limited with this parameter, to reduce the processing time.
var shape: Shape3D?
The
Shape3D
-derived shape to be used for collision queries.var targetPosition: Vector3
The shape’s destination point, relative to this node’s
position
.func addException(node: CollisionObject3D?
) Adds a collision exception so the shape does not report collisions with the specified
CollisionObject3D
node.func addExceptionRid(RID
) Adds a collision exception so the shape does not report collisions with the specified
RID
.func clearExceptions(
) Removes all collision exceptions for this
ShapeCast3D
.func 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.func getClosestCollisionSafeFraction(
) -> Double The fraction from the
ShapeCast3D
’s origin to itstargetPosition
(between 0 and 1) of how far the shape can move without triggering a collision.func getClosestCollisionUnsafeFraction(
) -> Double The fraction from the
ShapeCast3D
’s origin to itstargetPosition
(between 0 and 1) of how far the shape must move to trigger a collision.func getCollider(index: Int32
) -> Object? Returns the collided
Object
of one of the multiple collisions atindex
, ornull
if no object is intersecting the shape (i.e.isColliding
returnsfalse
).func getColliderRid(index: Int32
) -> RID Returns the
RID
of the collided object of one of the multiple collisions atindex
.func getColliderShape(index: Int32
) -> Int32 Returns the shape ID of the colliding shape of one of the multiple collisions at
index
, or0
if no object is intersecting the shape (i.e.isColliding
returnsfalse
).func getCollisionCount(
) -> Int32 The number of collisions detected at the point of impact. Use this to iterate over multiple collisions as provided by
getCollider(index:)
,getColliderShape(index:)
,getCollisionPoint(index:)
, andgetCollisionNormal(index:)
methods.func getCollisionMaskValue(layerNumber: Int32
) -> Bool Returns whether or not the specified layer of the
collisionMask
is enabled, given alayerNumber
between 1 and 32.func getCollisionNormal(index: Int32
) -> Vector3 Returns the normal of one of the multiple collisions at
index
of the intersecting object.func getCollisionPoint(index: Int32
) -> Vector3 Returns the collision point of one of the multiple collisions at
index
where the shape intersects the colliding object.func isColliding(
) -> Bool Returns whether any object is intersecting with the shape’s vector (considering the vector length).
func removeException(node: CollisionObject3D?
) Removes a collision exception so the shape does report collisions with the specified
CollisionObject3D
node.func removeExceptionRid(RID
) Removes a collision exception so the shape does report collisions with the specified
RID
.func resourceChanged(resource: Resource?
) Obsoleted. Use [signal Resource.changed] instead.
func setCollisionMaskValue(layerNumber: Int32, value: Bool
) Based on
value
, enables or disables the specified layer in thecollisionMask
, given alayerNumber
between 1 and 32.