Changed the note from information to suggestion. |
Update, correct and bring to parity with Raycast One page |
||
Line 22: | Line 22: | ||
|}} | |}} | ||
The | 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 [[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 | The starting position from which the ray is cast. Default is [0;0;0]. | ||
=== Direction ([[Type:float3|float3]]) === | === Direction ([[Type:float3|float3]]) === | ||
The direction | 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 | 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]]) === | ||
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]]) === | ||
Determines whether only user bone or simplified capsule colliders are valid targets. Default is False. | |||
=== Root ([[Slot]]) === | === Root ([[Slot]]) === | ||
The 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 [[Coordinate_spaces#Global_vs._Local | global coordinate space]]. | ||
== Outputs == | == Outputs == | ||
=== HitCollider ([[Type:ICollider|ICollider]]) === | === HitCollider ([[Type:ICollider|ICollider]]) === | ||
The collider | The first valid hit collider. | ||
=== HitDistance ([[Type:float|float]]) === | === HitDistance ([[Type:float|float]]) === | ||
The distance from | The distance from the Origin to the hit point in global coordinate space. | ||
=== HitPoint ([[Type:float3|float3]]) === | === HitPoint ([[Type:float3|float3]]) === | ||
The | The global position at which the ray hit the collider. | ||
=== HitNormal ([[Type:float3|float3]]) === | === HitNormal ([[Type:float3|float3]]) === | ||
The facing normal | The facing normal direction of the hit collider at the hit point. | ||
=== HitTriangleIndex ([[Type:int|int]]) === | === HitTriangleIndex ([[Type:int|int]]) === | ||
The triangle mesh | 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
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.
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.