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.
RayCast2D can ignore some objects by adding them to an exception list, by making its detection reporting ignore Area2Ds (CollideWithAreas) or PhysicsBody2Ds (CollideWithBodies), or by configuring physics layers.
RayCast2D 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 RayCast2D multiple times within the same physics frame, use ForceRaycastUpdate.
To sweep over a region of 2D space, you can approximate the region with multiple RayCast2Ds or use ShapeCast2D.
Index ¶
- type Advanced
- type Any
- type Extension
- type ID
- type Instance
- func (self Instance) AddException(node CollisionObject2D.Instance)
- func (self Instance) AddExceptionRid(rid RID.Body2D)
- func (self Instance) AsCanvasItem() CanvasItem.Instance
- func (self Instance) AsNode() Node.Instance
- func (self Instance) AsNode2D() Node2D.Instance
- func (self Instance) AsObject() [1]gd.Object
- func (self Instance) AsRayCast2D() Instance
- func (self Instance) ClearExceptions()
- func (self Instance) CollideWithAreas() bool
- func (self Instance) CollideWithBodies() bool
- func (self Instance) CollisionMask() int
- func (self Instance) Enabled() bool
- func (self Instance) ExcludeParent() bool
- func (self Instance) ForceRaycastUpdate()
- func (self Instance) GetCollider() Object.Instance
- func (self Instance) GetColliderRid() RID.Body2D
- func (self Instance) GetColliderShape() int
- func (self Instance) GetCollisionMaskValue(layer_number int) bool
- func (self Instance) GetCollisionNormal() Vector2.XY
- func (self Instance) GetCollisionPoint() Vector2.XY
- func (self Instance) HitFromInside() bool
- func (self Instance) ID() ID
- func (self Instance) IsColliding() bool
- func (self Instance) RemoveException(node CollisionObject2D.Instance)
- func (self Instance) RemoveExceptionRid(rid RID.Body2D)
- 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) SetEnabled(value bool)
- func (self Instance) SetExcludeParent(value bool)
- func (self Instance) SetHitFromInside(value bool)
- func (self *Instance) SetObject(obj [1]gd.Object) bool
- func (self Instance) SetTargetPosition(value Vector2.XY)
- func (self Instance) TargetPosition() Vector2.XY
- func (self Instance) Virtual(name string) reflect.Value
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]) AsCanvasItem ¶
func (self *Extension[T]) AsCanvasItem() CanvasItem.Instance
func (*Extension[T]) AsRayCast2D ¶
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 ¶
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 CollisionObject2D.Instance)
Adds a collision exception so the ray does not report collisions with the specified 'node'.
func (Instance) AddExceptionRid ¶
Adds a collision exception so the ray does not report collisions with the specified Resource.ID.
func (Instance) AsCanvasItem ¶
func (self Instance) AsCanvasItem() CanvasItem.Instance
func (Instance) AsRayCast2D ¶
func (Instance) ClearExceptions ¶
func (self Instance) ClearExceptions()
Removes all collision exceptions for this ray.
func (Instance) CollideWithAreas ¶
If true, collisions with Area2Ds will be reported.
func (Instance) CollideWithBodies ¶
If true, collisions with PhysicsBody2Ds will be reported.
func (Instance) CollisionMask ¶
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) ExcludeParent ¶
If true, this raycast will not report collisions with its parent node. This property only has an effect if the parent node is a CollisionObject2D. 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 ¶
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 CollisionObject2D. For example, if the ray intersects a TileMapLayer, the method will return a TileMapLayer instance.
func (Instance) GetColliderRid ¶
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 ¶
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 CollisionObject2D target, use:
var target = Object.To[CollisionObject2D.Instance](rayCast2D.GetCollider()) // A CollisionObject2D. var shapeID int = rayCast2D.GetColliderShape() var ownerID int = target.ShapeFindOwner(shapeID) // The owner ID in the collider. var shape = target.ShapeOwnerGetOwner(ownerID)
func (Instance) GetCollisionMaskValue ¶
Returns whether or not the specified layer of the CollisionMask is enabled, given a 'layer_number' between 1 and 32.
func (Instance) GetCollisionNormal ¶
Returns the normal of the intersecting object's shape at the collision point, or Vector2(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 ¶
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) HitFromInside ¶
If true, the ray will detect a hit when starting inside shapes. In this case the collision normal will be Vector2(0, 0). Does not affect concave polygon shapes.
func (Instance) IsColliding ¶
Returns whether any object is intersecting with the ray's vector (considering the vector length).
func (Instance) RemoveException ¶
func (self Instance) RemoveException(node CollisionObject2D.Instance)
Removes a collision exception so the ray can report collisions with the specified specified 'node'.
func (Instance) RemoveExceptionRid ¶
Removes a collision exception so the ray can report collisions with the specified Resource.ID.
func (Instance) SetCollideWithAreas ¶
SetCollideWithAreas sets the property returned by [IsCollideWithAreasEnabled].
func (Instance) SetCollideWithBodies ¶
SetCollideWithBodies sets the property returned by [IsCollideWithBodiesEnabled].
func (Instance) SetCollisionMask ¶
SetCollisionMask sets the property returned by [GetCollisionMask].
func (Instance) SetCollisionMaskValue ¶
Based on 'value', enables or disables the specified layer in the CollisionMask, given a 'layer_number' between 1 and 32.
func (Instance) SetEnabled ¶
SetEnabled sets the property returned by [IsEnabled].
func (Instance) SetExcludeParent ¶
SetExcludeParent sets the property returned by [GetExcludeParentBody].
func (Instance) SetHitFromInside ¶
SetHitFromInside sets the property returned by [IsHitFromInsideEnabled].
func (Instance) SetTargetPosition ¶
SetTargetPosition sets the property returned by [GetTargetPosition].
func (Instance) TargetPosition ¶
The ray's destination point, relative to this raycast's Node2D.Position.