RayCast3D

package
v0.0.0-...-357ca8a Latest Latest
Warning

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

Go to latest
Published: Sep 20, 2025 License: MIT Imports: 28 Imported by: 0

Documentation

Overview

A raycast represents a ray from its origin to its TargetPosition that finds the closest object along its path, if it intersects any.

RayCast3D can ignore some objects by adding them to an exception list, by making its detection reporting ignore Area3Ds (CollideWithAreas) or PhysicsBody3Ds (CollideWithBodies), or by configuring physics layers.

RayCast3D calculates intersection every physics frame, and it holds the result until the next physics frame. For an immediate raycast, or if you want to configure a RayCast3D multiple times within the same physics frame, use ForceRaycastUpdate.

To sweep over a region of 3D space, you can approximate the region with multiple RayCast3Ds or use ShapeCast3D.

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
	AsRayCast3D() 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]) AsRayCast3D

func (self *Extension[T]) AsRayCast3D() 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.RayCast3D

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 ray does not report collisions with the specified 'node'.

func (Instance) AddExceptionRid

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

Adds a collision exception so the ray 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) AsRayCast3D

func (self Instance) AsRayCast3D() Instance

func (Instance) ClearExceptions

func (self Instance) ClearExceptions()

Removes all collision exceptions for this ray.

func (Instance) CollideWithAreas

func (self Instance) CollideWithAreas() bool

If true, collisions with Area3Ds will be reported.

func (Instance) CollideWithBodies

func (self Instance) CollideWithBodies() bool

If true, collisions with PhysicsBody3Ds will be reported.

func (Instance) CollisionMask

func (self Instance) CollisionMask() int

The ray'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.

func (Instance) DebugShapeCustomColor

func (self Instance) DebugShapeCustomColor() Color.RGBA

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 RayCast3D 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.

func (Instance) DebugShapeThickness

func (self Instance) DebugShapeThickness() int

If set to 1, a line is used as the debug shape. Otherwise, a truncated pyramid is drawn to represent the RayCast3D. Requires Visible Collision Shapes to be enabled in the Debug menu for the debug shape to be visible at run-time.

func (Instance) Enabled

func (self Instance) Enabled() bool

If true, collisions will be reported.

func (Instance) ExcludeParent

func (self Instance) ExcludeParent() bool

If true, this raycast will not report collisions with its parent node. This property only has an effect if the parent node is a CollisionObject3D. See also Node.GetParent and AddException.

func (Instance) ForceRaycastUpdate

func (self Instance) ForceRaycastUpdate()

Updates the collision information for the ray immediately, without waiting for the next _physics_process call. Use this method, for example, when the ray or its parent has changed state.

Note: Enabled does not need to be true for this to work.

func (Instance) GetCollider

func (self Instance) GetCollider() Object.Instance

Returns the first object that the ray intersects, or null if no object is intersecting the ray (i.e. IsColliding returns false).

Note: This object is not guaranteed to be a CollisionObject3D. For example, if the ray intersects a CSGShape3D or a GridMap, the method will return a CSGShape3D or GridMap instance.

func (Instance) GetColliderRid

func (self Instance) GetColliderRid() RID.Body3D

Returns the Resource.ID of the first object that the ray intersects, or an empty Resource.ID if no object is intersecting the ray (i.e. IsColliding returns false).

func (Instance) GetColliderShape

func (self Instance) GetColliderShape() int

Returns the shape ID of the first object that the ray intersects, or 0 if no object is intersecting the ray (i.e. IsColliding returns false).

To get the intersected shape node, for a CollisionObject3D target, use:

var target = Object.To[CollisionObject3D.Instance](rayCast3D.GetCollider()) // A CollisionObject3D.
var shapeID int = rayCast3D.GetColliderShape()
var ownerID int = target.ShapeFindOwner(shapeID)
var shape = target.ShapeOwnerGetOwner(ownerID)

func (Instance) GetCollisionFaceIndex

func (self Instance) GetCollisionFaceIndex() int

Returns the collision object's face index at the collision point, or -1 if the shape intersecting the ray is not a ConcavePolygonShape3D.

func (Instance) GetCollisionMaskValue

func (self Instance) GetCollisionMaskValue(layer_number int) bool

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

func (Instance) GetCollisionNormal

func (self Instance) GetCollisionNormal() Vector3.XYZ

Returns the normal of the intersecting object's shape at the collision point, or Vector3(0, 0, 0) if the ray starts inside the shape and HitFromInside is true.

Note: Check that IsColliding returns true before calling this method to ensure the returned normal is valid and up-to-date.

func (Instance) GetCollisionPoint

func (self Instance) GetCollisionPoint() Vector3.XYZ

Returns the collision point at which the ray intersects the closest object, in the global coordinate system. If HitFromInside is true and the ray starts inside of a collision shape, this function will return the origin point of the ray.

Note: Check that IsColliding returns true before calling this method to ensure the returned point is valid and up-to-date.

func (Instance) HitBackFaces

func (self Instance) HitBackFaces() bool

If true, the ray will hit back faces with concave polygon shapes with back face enabled or heightmap shapes.

func (Instance) HitFromInside

func (self Instance) HitFromInside() bool

If true, the ray will detect a hit when starting inside shapes. In this case the collision normal will be Vector3(0, 0, 0). Does not affect shapes with no volume like concave polygon or heightmap.

func (Instance) ID

func (self Instance) ID() ID

func (Instance) IsColliding

func (self Instance) IsColliding() bool

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

func (Instance) RemoveException

func (self Instance) RemoveException(node CollisionObject3D.Instance)

Removes a collision exception so the ray can report collisions with the specified 'node'.

func (Instance) RemoveExceptionRid

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

Removes a collision exception so the ray can report collisions with the specified Resource.ID.

func (Instance) SetCollideWithAreas

func (self Instance) SetCollideWithAreas(value bool)

SetCollideWithAreas sets the property returned by [IsCollideWithAreasEnabled].

func (Instance) SetCollideWithBodies

func (self Instance) SetCollideWithBodies(value bool)

SetCollideWithBodies sets the property returned by [IsCollideWithBodiesEnabled].

func (Instance) SetCollisionMask

func (self Instance) SetCollisionMask(value int)

SetCollisionMask sets the property returned by [GetCollisionMask].

func (Instance) SetCollisionMaskValue

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

Based on 'value', enables or disables the specified layer in the CollisionMask, given a 'layer_number' between 1 and 32.

func (Instance) SetDebugShapeCustomColor

func (self Instance) SetDebugShapeCustomColor(value Color.RGBA)

SetDebugShapeCustomColor sets the property returned by [GetDebugShapeCustomColor].

func (Instance) SetDebugShapeThickness

func (self Instance) SetDebugShapeThickness(value int)

SetDebugShapeThickness sets the property returned by [GetDebugShapeThickness].

func (Instance) SetEnabled

func (self Instance) SetEnabled(value bool)

SetEnabled sets the property returned by [IsEnabled].

func (Instance) SetExcludeParent

func (self Instance) SetExcludeParent(value bool)

SetExcludeParent sets the property returned by [GetExcludeParentBody].

func (Instance) SetHitBackFaces

func (self Instance) SetHitBackFaces(value bool)

SetHitBackFaces sets the property returned by [IsHitBackFacesEnabled].

func (Instance) SetHitFromInside

func (self Instance) SetHitFromInside(value bool)

SetHitFromInside sets the property returned by [IsHitFromInsideEnabled].

func (*Instance) SetObject

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

func (Instance) SetTargetPosition

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

SetTargetPosition sets the property returned by [GetTargetPosition].

func (Instance) TargetPosition

func (self Instance) TargetPosition() Vector3.XYZ

The ray's destination point, relative to this raycast's Node3D.Position.

func (Instance) Virtual

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

Jump to

Keyboard shortcuts

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