Documentation
¶
Overview ¶
Shape casting allows to detect collision objects by sweeping its Instance.Shape along the cast direction determined by Instance.TargetPosition. This is similar to graphics.gd/classdb/RayCast3D, but it allows for sweeping a region of space, rather than just a straight line. graphics.gd/classdb/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 Instance.TargetPosition set to Vector3(0, 0, 0) and by calling Instance.ForceShapecastUpdate within the same physics frame. This helps to overcome some limitations of graphics.gd/classdb/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.
Index ¶
- type Advanced
- type Any
- type Extension
- type ID
- type Instance
- func (self Instance) AddException(node CollisionObject3D.Instance)
- func (self Instance) AddExceptionRid(rid RID.Body3D)
- func (self Instance) AsNode() Node.Instance
- func (self Instance) AsNode3D() Node3D.Instance
- func (self Instance) AsObject() [1]gd.Object
- func (self Instance) AsShapeCast3D() Instance
- func (self Instance) ClearExceptions()
- func (self Instance) CollideWithAreas() bool
- func (self Instance) CollideWithBodies() bool
- func (self Instance) CollisionMask() int
- func (self Instance) CollisionResult() []PhysicsDirectSpaceState3D_RestInfo
- func (self Instance) DebugShapeCustomColor() Color.RGBA
- func (self Instance) Enabled() bool
- func (self Instance) ExcludeParent() bool
- func (self Instance) ForceShapecastUpdate()
- func (self Instance) GetClosestCollisionSafeFraction() Float.X
- func (self Instance) GetClosestCollisionUnsafeFraction() Float.X
- func (self Instance) GetCollider(index int) Object.Instance
- func (self Instance) GetColliderRid(index int) RID.Body3D
- func (self Instance) GetColliderShape(index int) int
- func (self Instance) GetCollisionCount() int
- func (self Instance) GetCollisionMaskValue(layer_number int) bool
- func (self Instance) GetCollisionNormal(index int) Vector3.XYZ
- func (self Instance) GetCollisionPoint(index int) Vector3.XYZ
- func (self Instance) ID() ID
- func (self Instance) IsColliding() bool
- func (self Instance) Margin() Float.X
- func (self Instance) MaxResults() int
- func (self Instance) RemoveException(node CollisionObject3D.Instance)
- func (self Instance) RemoveExceptionRid(rid RID.Body3D)
- func (self Instance) ResourceChanged(resource Resource.Instance)
- func (self Instance) SetCollideWithAreas(value bool)
- func (self Instance) SetCollideWithBodies(value bool)
- func (self Instance) SetCollisionMask(value int)
- func (self Instance) SetCollisionMaskValue(layer_number int, value bool)
- func (self Instance) SetDebugShapeCustomColor(value Color.RGBA)
- func (self Instance) SetEnabled(value bool)
- func (self Instance) SetExcludeParent(value bool)
- func (self Instance) SetMargin(value Float.X)
- func (self Instance) SetMaxResults(value int)
- func (self *Instance) SetObject(obj [1]gd.Object) bool
- func (self Instance) SetShape(value Shape3D.Instance)
- func (self Instance) SetTargetPosition(value Vector3.XYZ)
- func (self Instance) Shape() Shape3D.Instance
- func (self Instance) TargetPosition() Vector3.XYZ
- func (self Instance) Virtual(name string) reflect.Value
- type PhysicsDirectSpaceState3D_RestInfo
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 Extension ¶
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]) AsShapeCast3D ¶
type 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.
type Instance ¶
type Instance [1]gdclass.ShapeCast3D
Instance of the class with convieniently typed arguments and results.
var Nil Instance
Nil is a nil/null instance of the class. Equivalent to the zero value.
func (Instance) AddException ¶
func (self Instance) AddException(node CollisionObject3D.Instance)
Adds a collision exception so the shape does not report collisions with the specified node.
func (Instance) AddExceptionRid ¶
Adds a collision exception so the shape does not report collisions with the specified [Resource.ID].
func (Instance) AsShapeCast3D ¶
func (Instance) ClearExceptions ¶
func (self Instance) ClearExceptions()
Removes all collision exceptions for this shape.
func (Instance) CollideWithAreas ¶
func (Instance) CollideWithBodies ¶
func (Instance) CollisionMask ¶
func (Instance) CollisionResult ¶
func (self Instance) CollisionResult() []PhysicsDirectSpaceState3D_RestInfo
func (Instance) DebugShapeCustomColor ¶
func (Instance) ExcludeParent ¶
func (Instance) ForceShapecastUpdate ¶
func (self Instance) 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: Setting Instance.Enabled to true is not required for this to work.
func (Instance) GetClosestCollisionSafeFraction ¶
Returns the fraction from this cast's origin to its Instance.TargetPosition of how far the shape can move without triggering a collision, as a value between 0.0 and 1.0.
func (Instance) GetClosestCollisionUnsafeFraction ¶
Returns the fraction from this cast's origin to its Instance.TargetPosition of how far the shape must move to trigger a collision, as a value between 0.0 and 1.0.
In ideal conditions this would be the same as Instance.GetClosestCollisionSafeFraction, however shape casting is calculated in discrete steps, so the precise point of collision can occur between two calculated positions.
func (Instance) GetCollider ¶
Returns the collided graphics.gd/classdb/Object of one of the multiple collisions at 'index', or null if no object is intersecting the shape (i.e. Instance.IsColliding returns false).
func (Instance) GetColliderRid ¶
Returns the [Resource.ID] of the collided object of one of the multiple collisions at 'index'.
func (Instance) GetColliderShape ¶
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. Instance.IsColliding returns false).
func (Instance) GetCollisionCount ¶
The number of collisions detected at the point of impact. Use this to iterate over multiple collisions as provided by Instance.GetCollider, Instance.GetColliderShape, Instance.GetCollisionPoint, and Instance.GetCollisionNormal methods.
func (Instance) GetCollisionMaskValue ¶
Returns whether or not the specified layer of the Instance.CollisionMask is enabled, given a 'layer_number' between 1 and 32.
func (Instance) GetCollisionNormal ¶
Returns the normal of one of the multiple collisions at 'index' of the intersecting object.
func (Instance) GetCollisionPoint ¶
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.
func (Instance) IsColliding ¶
Returns whether any object is intersecting with the shape's vector (considering the vector length).
func (Instance) MaxResults ¶
func (Instance) RemoveException ¶
func (self Instance) RemoveException(node CollisionObject3D.Instance)
Removes a collision exception so the shape does report collisions with the specified node.
func (Instance) RemoveExceptionRid ¶
Removes a collision exception so the shape does report collisions with the specified [Resource.ID].
func (Instance) ResourceChanged ¶
This method does nothing.
func (Instance) SetCollideWithAreas ¶
func (Instance) SetCollideWithBodies ¶
func (Instance) SetCollisionMask ¶
func (Instance) SetCollisionMaskValue ¶
Based on 'value', enables or disables the specified layer in the Instance.CollisionMask, given a 'layer_number' between 1 and 32.
func (Instance) SetDebugShapeCustomColor ¶
func (Instance) SetEnabled ¶
func (Instance) SetExcludeParent ¶
func (Instance) SetMaxResults ¶
func (Instance) SetTargetPosition ¶
func (Instance) TargetPosition ¶
type PhysicsDirectSpaceState3D_RestInfo ¶
type PhysicsDirectSpaceState3D_RestInfo struct { ColliderID Object.ID `gd:"collider_id"` LinearVelocity struct { X float32 Y float32 Z float32 } `gd:"linear_velocity"` Normal struct { X float32 Y float32 Z float32 } `gd:"normal"` Point struct { X float32 Y float32 Z float32 } `gd:"point"` RID RID.Any `gd:"rid"` Shape int `gd:"shape"` }