ProtoFlux:Raycaster: Difference between revisions

From Resonite Wiki
Changed the note from information to suggestion.
Update, correct and bring to parity with Raycast One page
 
Line 22: Line 22:
|}}
|}}


The <code>Raycaster</code> node allows raycast checks, and can take in parameters that sets up the raycast and the validity of what it checks for. When this raycast detects a valid collider, it returns data pertaining to that hit.
The '''Raycaster''' node performs a raycast check every update, essentially acting as a constant raycast. The input parameters determine from where, in what direction, and how far the ray should be cast as well as determining which colliders are valid hits. When a raycast detects a valid collider, it returns data pertaining to that hit from the node outputs.


This node returns data per frame, and is very useful for debugging and testing hit detection due to its constant updates.
This node can be combined with the [[ProtoFlux:Hit UV Coordinate|Hit UV Coordinate]] node to get further data from this hit, such as a 2D location point on the collider for example. Since this node returns data per frame, it can be very useful for debugging and testing raycast hit detection.
 
This node can be combined with the [[ProtoFlux:Hit UV Coordinate|Hit UV Coordinate]] node to get further data from this hit, such as a 2D location point on the collider for example.


{{Note|If you want the same functionality as this node, but want to control when it checks for valid hits, use [[ProtoFlux:Raycast One|Raycast One]] instead.|suggestion}}
{{Note|If you want the same functionality as this node, but want to control when it checks for valid hits, use [[ProtoFlux:Raycast One|Raycast One]] instead.|suggestion}}
Line 34: Line 32:
=== Origin ([[Type:float3|float3]]) ===  
=== Origin ([[Type:float3|float3]]) ===  


The point where we start this raycast.
The starting position from which the ray is cast. Default is [0;0;0].


=== Direction ([[Type:float3|float3]]) ===  
=== Direction ([[Type:float3|float3]]) ===  


The direction where this raycast should go in.
The direction in which the ray is cast. Default is [0;0;0] which results in no ray being cast.


=== MaxDistance ([[Type:float|float]]) ===  
=== MaxDistance ([[Type:float|float]]) ===  


The maximum distance this raycast should go.
The maximum distance the raycast should travel from its origin. Default is the maximum float value which is extremely high.


=== HitTriggers ([[Type:bool|bool]]) ===  
=== HitTriggers ([[Type:bool|bool]]) ===  


Should this raycast hit trigger colliders.
Determines whether colliders with the Trigger, StaticTrigger or StaticTriggerAuto ColliderType value are valid hit targets. Default is False.


=== UsersOnly ([[Type:bool|bool]]) ===  
=== UsersOnly ([[Type:bool|bool]]) ===  


Should this raycast only hit users.
Determines whether only user bone or simplified capsule colliders are valid targets. Default is False.  


=== Root ([[Slot]]) ===  
=== Root ([[Slot]]) ===  


The slot hierarchy this raycast should check for when hitting slots, and only return data from slots it hit from within that slot hierarchy.
The slot in whose coordinate space the Origin, Direction and MaxDistance values should be evaluated. Default is the world root slot, i.e. the values are treated as being in the [[Coordinate_spaces#Global_vs._Local | global coordinate space]].


== Outputs ==
== Outputs ==
=== HasHit ([[Type:bool|bool]]) ===
Returns if the raycast hit anything that is valid.


=== HitCollider ([[Type:ICollider|ICollider]]) ===
=== HitCollider ([[Type:ICollider|ICollider]]) ===


The collider we detected from this raycast.
The first valid hit collider.


=== HitDistance ([[Type:float|float]]) ===
=== HitDistance ([[Type:float|float]]) ===


The distance from where we hit a valid collider.
The distance from the Origin to the hit point in global coordinate space.


=== HitPoint ([[Type:float3|float3]]) ===
=== HitPoint ([[Type:float3|float3]]) ===


The point in 3D space where we hit this valid collider.
The global position at which the ray hit the collider.


=== HitNormal ([[Type:float3|float3]]) ===
=== HitNormal ([[Type:float3|float3]]) ===


The facing normal that we hit from a valid collider.
The facing normal direction of the hit collider at the hit point.


=== HitTriangleIndex ([[Type:int|int]]) ===
=== HitTriangleIndex ([[Type:int|int]]) ===


The triangle mesh number we hit.
The triangle index on the mesh corresponding to the hit collider. This value is 0 unless the HitCollider is a MeshCollider.
 
== Usage ==
There are a few ways in which the Raycaster node may not work as expected, particularly relating to directions and distances.
 
Firstly, the global scale of the input Root slot is taken into account when calculating a raycast's path. For example, assume that the Root slot input has global position [0;0;0] and global scale [0.1;0.1;0.1]; if the Origin input is [0;0;0], the raycast will start at global [0;0;0], however, if the Origin input is [0;1;0] the raycast will start at global [0;0.1;0] not global [0;1;0].
Similarly, the input Root slot's global scale affects the Direction vector and MaxDistance values too. With the same example input Root slot, a Direction of [0;0;1] and a MaxDistance of 1 result in a ray which travels only 0.1 units.
 
Secondly, the magnitude of the Direction vector affects the distance that the ray travels and the reported HitDistance output value. Assuming no input Root slot, a Direction input of [0;0;1] and MaxDistance of 1 will produce a ray 1 unit long. However, a Direction input of [0;0;2] and MaxDistance of 1 will produce a ray 2 units long. Additionally, the reported HitDistance value will be halved in the second case.


[[Category:ProtoFlux:Physics]]
[[Category:ProtoFlux:Physics]]

Latest revision as of 06:19, 26 May 2024

Raycaster
Origin
HasHit
Direction
HitCollider
MaxDistance
HitDistance
HitTriggers
HitPoint
UsersOnly
HitNormal
Root
HitTriangleIndex
Physics

The Raycaster node performs a raycast check every update, essentially acting as a constant raycast. The input parameters determine from where, in what direction, and how far the ray should be cast as well as determining which colliders are valid hits. When a raycast detects a valid collider, it returns data pertaining to that hit from the node outputs.

This node can be combined with the Hit UV Coordinate node to get further data from this hit, such as a 2D location point on the collider for example. Since this node returns data per frame, it can be very useful for debugging and testing raycast hit detection.

If you want the same functionality as this node, but want to control when it checks for valid hits, use Raycast One instead.

Inputs

Origin (float3)

The starting position from which the ray is cast. Default is [0;0;0].

Direction (float3)

The direction in which the ray is cast. Default is [0;0;0] which results in no ray being cast.

MaxDistance (float)

The maximum distance the raycast should travel from its origin. Default is the maximum float value which is extremely high.

HitTriggers (bool)

Determines whether colliders with the Trigger, StaticTrigger or StaticTriggerAuto ColliderType value are valid hit targets. Default is False.

UsersOnly (bool)

Determines whether only user bone or simplified capsule colliders are valid targets. Default is False.

Root (Slot)

The slot in whose coordinate space the Origin, Direction and MaxDistance values should be evaluated. Default is the world root slot, i.e. the values are treated as being in the global coordinate space.

Outputs

HitCollider (ICollider)

The first valid hit collider.

HitDistance (float)

The distance from the Origin to the hit point in global coordinate space.

HitPoint (float3)

The global position at which the ray hit the collider.

HitNormal (float3)

The facing normal direction of the hit collider at the hit point.

HitTriangleIndex (int)

The triangle index on the mesh corresponding to the hit collider. This value is 0 unless the HitCollider is a MeshCollider.

Usage

There are a few ways in which the Raycaster node may not work as expected, particularly relating to directions and distances.

Firstly, the global scale of the input Root slot is taken into account when calculating a raycast's path. For example, assume that the Root slot input has global position [0;0;0] and global scale [0.1;0.1;0.1]; if the Origin input is [0;0;0], the raycast will start at global [0;0;0], however, if the Origin input is [0;1;0] the raycast will start at global [0;0.1;0] not global [0;1;0]. Similarly, the input Root slot's global scale affects the Direction vector and MaxDistance values too. With the same example input Root slot, a Direction of [0;0;1] and a MaxDistance of 1 result in a ray which travels only 0.1 units.

Secondly, the magnitude of the Direction vector affects the distance that the ray travels and the reported HitDistance output value. Assuming no input Root slot, a Direction input of [0;0;1] and MaxDistance of 1 will produce a ray 1 unit long. However, a Direction input of [0;0;2] and MaxDistance of 1 will produce a ray 2 units long. Additionally, the reported HitDistance value will be halved in the second case.