ShapeCast3D

package
v0.0.0-...-535787f Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 16, 2025 License: MIT Imports: 29 Imported by: 0

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

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 Any

type Any interface {
	gd.IsClass
	AsShapeCast3D() Instance
}

type Extension

type Extension[T gdclass.Interface] struct{ gdclass.Extension[T, Instance] }

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]) AsNode

func (self *Extension[T]) AsNode() Node.Instance

func (*Extension[T]) AsNode3D

func (self *Extension[T]) AsNode3D() Node3D.Instance

func (*Extension[T]) AsObject

func (self *Extension[T]) AsObject() [1]gd.Object

func (*Extension[T]) AsShapeCast3D

func (self *Extension[T]) AsShapeCast3D() Instance

type ID

type ID Object.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.

func (ID) Instance

func (id ID) Instance() (Instance, bool)

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 New

func New() Instance

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

func (self Instance) AddExceptionRid(rid RID.Body3D)

Adds a collision exception so the shape does not report collisions with the specified [Resource.ID].

func (Instance) AsNode

func (self Instance) AsNode() Node.Instance

func (Instance) AsNode3D

func (self Instance) AsNode3D() Node3D.Instance

func (Instance) AsObject

func (self Instance) AsObject() [1]gd.Object

func (Instance) AsShapeCast3D

func (self Instance) AsShapeCast3D() Instance

func (Instance) ClearExceptions

func (self Instance) ClearExceptions()

Removes all collision exceptions for this shape.

func (Instance) CollideWithAreas

func (self Instance) CollideWithAreas() bool

func (Instance) CollideWithBodies

func (self Instance) CollideWithBodies() bool

func (Instance) CollisionMask

func (self Instance) CollisionMask() int

func (Instance) CollisionResult

func (self Instance) CollisionResult() []PhysicsDirectSpaceState3D_RestInfo

func (Instance) DebugShapeCustomColor

func (self Instance) DebugShapeCustomColor() Color.RGBA

func (Instance) Enabled

func (self Instance) Enabled() bool

func (Instance) ExcludeParent

func (self Instance) ExcludeParent() bool

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

func (self Instance) GetClosestCollisionSafeFraction() Float.X

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

func (self Instance) GetClosestCollisionUnsafeFraction() Float.X

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

func (self Instance) GetCollider(index int) Object.Instance

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

func (self Instance) GetColliderRid(index int) RID.Body3D

Returns the [Resource.ID] of the collided object of one of the multiple collisions at 'index'.

func (Instance) GetColliderShape

func (self Instance) GetColliderShape(index int) 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. Instance.IsColliding returns false).

func (Instance) GetCollisionCount

func (self Instance) GetCollisionCount() int

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

func (self Instance) GetCollisionMaskValue(layer_number int) bool

Returns whether or not the specified layer of the Instance.CollisionMask is enabled, given a 'layer_number' between 1 and 32.

func (Instance) GetCollisionNormal

func (self Instance) GetCollisionNormal(index int) Vector3.XYZ

Returns the normal of one of the multiple collisions at 'index' of the intersecting object.

func (Instance) GetCollisionPoint

func (self Instance) GetCollisionPoint(index int) Vector3.XYZ

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) ID

func (self Instance) ID() ID

func (Instance) IsColliding

func (self Instance) IsColliding() bool

Returns whether any object is intersecting with the shape's vector (considering the vector length).

func (Instance) Margin

func (self Instance) Margin() Float.X

func (Instance) MaxResults

func (self Instance) MaxResults() int

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

func (self Instance) RemoveExceptionRid(rid RID.Body3D)

Removes a collision exception so the shape does report collisions with the specified [Resource.ID].

func (Instance) ResourceChanged

func (self Instance) ResourceChanged(resource Resource.Instance)

This method does nothing.

func (Instance) SetCollideWithAreas

func (self Instance) SetCollideWithAreas(value bool)

func (Instance) SetCollideWithBodies

func (self Instance) SetCollideWithBodies(value bool)

func (Instance) SetCollisionMask

func (self Instance) SetCollisionMask(value int)

func (Instance) SetCollisionMaskValue

func (self Instance) SetCollisionMaskValue(layer_number int, value bool)

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 (self Instance) SetDebugShapeCustomColor(value Color.RGBA)

func (Instance) SetEnabled

func (self Instance) SetEnabled(value bool)

func (Instance) SetExcludeParent

func (self Instance) SetExcludeParent(value bool)

func (Instance) SetMargin

func (self Instance) SetMargin(value Float.X)

func (Instance) SetMaxResults

func (self Instance) SetMaxResults(value int)

func (*Instance) SetObject

func (self *Instance) SetObject(obj [1]gd.Object) bool

func (Instance) SetShape

func (self Instance) SetShape(value Shape3D.Instance)

func (Instance) SetTargetPosition

func (self Instance) SetTargetPosition(value Vector3.XYZ)

func (Instance) Shape

func (self Instance) Shape() Shape3D.Instance

func (Instance) TargetPosition

func (self Instance) TargetPosition() Vector3.XYZ

func (Instance) Virtual

func (self Instance) Virtual(name string) reflect.Value

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"`
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL