Component:RaycastDriver: Difference between revisions

From Resonite Wiki
Add related
Automated: update Categories
 
(One intermediate revision by one other user not shown)
Line 2: Line 2:
<translate>
<translate>
<!--T:1-->
<!--T:1-->
{{stub}}
{{Infobox Component
{{Infobox Component
|Image=RaycastDriverComponent.png
|Image=RaycastDriverComponent.png
|Name=Raycast Driver
|Name=RaycastDriver
}}
}}
Raycast driver drives the position of a slot to the position of a calculated hit point, and aligns it's rotation to the surface of that hit object.
 
The '''RaycastDriver''' component drives the position of the [[Slot]] it is attached to to the location of the hit point of a raycast and aligns its rotation to the normal of the hit object.


<!--T:2-->
<!--T:2-->
== Fields ==
== Fields ==
{{Table ComponentFields
{{Table ComponentFields
|IgnoreHierarchy|Slot| a hiearchy of slots which to ignore the colliders for
|IgnoreHierarchy|Slot|a hiearchy of slots which to ignore the colliders for
|FilterDistance|Float| ignore hit detections before this distance.
|FilterDistance|Float|ignore hit detections before this distance.
|Origin|Slot| The slot to start the raycast from.
|Origin|Slot|The slot to start the raycast from.
|Offset|Float3| The offset from <code>Origin</code> before starting the raycast.
|Offset|Float3|The offset from <code>Origin</code> before starting the raycast.
|Direction|Float3| The direction in <code>Origin</code>'s local space to shoot in.
|Direction|Float3|The direction in <code>Origin</code>'s local space to shoot in.
|MaxDistance|Float| The maximum distance to raycast for.
|MaxDistance|Float|The maximum distance to raycast for.
|NoHitDistance|Float| How far to raycast shoot for in meters till reporting no hit.
|NoHitDistance|Float|How far to raycast shoot for in meters till reporting no hit.
|Filter|{{RootFieldType|SyncDelegate`1|[[Type:Func`2|Func`2]]&lt;[[Type:ICollider|ICollider]], [[Type:Bool|Bool]]&gt;}}|TypeAdv7=true| A [[Sync Delegate|sync delegate]] that takes a collider and returns a bool. if a collider returns false from this sync delegate, it is ignored when raycasting for objects.
|Filter|{{RootFieldType|SyncDelegate`1|[[Type:Func`2|Func`2]]&lt;[[Type:ICollider|ICollider]], [[Type:Bool|Bool]]&gt;}}|TypeAdv7=true|A [[Sync Delegate|sync delegate]] that takes a collider and returns a bool. if a collider returns false from this sync delegate, it is ignored when raycasting for objects.
|_positionDrive|{{RootFieldType|FieldDrive`1|[[Type:Float3|Float3]]}}|TypeAdv8=true| The position to drive (usually the position of the slot this component is on)
|_positionDrive|{{RootFieldType|FieldDrive`1|[[Type:Float3|Float3]]}}|TypeAdv8=true|The position field to drive. This does not actually affect the field that is driven, but if it is not filled, the component will not function.
|_rotationDrive|{{RootFieldType|FieldDrive`1|[[Type:FloatQ|FloatQ]]}}|TypeAdv9=true| The rotation to drive (usually the rotation of the slot this component is on). aligns itself to the normal of the surface this raycast hit, or (0,0,0).
|_rotationDrive|{{RootFieldType|FieldDrive`1|[[Type:FloatQ|FloatQ]]}}|TypeAdv9=true|The rotation field to drive. This does not actually affect the field that is driven, but if it is not filled, the rotation of the slot is not changed. Aligns itself to the normal of the surface this raycast hit, or <code>(0,0,0)</code>.
}}
}}


<!--T:3-->
<!--T:3-->
== Usage ==
== Usage ==
When placed on a slot, <code>_positionDrive</code> and <code>_rotationDrive</code> are automatically filled to the slot's position and rotation. These fields are not actually effective, as this component always writes to the position/rotation of the slot it is on. However, if either of these fields are omitted, the respective functionality of the raycast is not performed.
The raycast is constructed in the [[local coordinate space]] of <code>Origin</code>, where <code>Offset</code> controls the origin of the ray relative to the origin and <code>Direction</code> controls the direction of the ray relative to the origin.
<code>MaxDistance</code> controls the maximum distance that the raycast will travel. If a raycast is unable to make contact with a collider within this distance, the position of the slot will be set to <code>NoHitDistance</code> in the direction of the raycast. <strong>These two distances are in global scale</strong>, and are <em>not</em> affected by either the slot's local scale or the scale of the <code>Origin</code> slot.
If the ray hits a collider, the rotation of the slot will be aligned to the normal of the hit point. This rotation can be transformed into the normal vector by using the [[ProtoFlux:Get Forward|Get Forward]] node on the RaycastDriver slot. If the raycast does not hit a collider, the rotation will be set to <code>(0, 0, 0)</code>.
=== Filtering ===
There are two ways of filtering what colliders the raycast is able to make contact with.
If <code>IgnoreHierarchy</code> is filled, the raycast will ignore all colliders present under the provided hierarchy. This can be useful if one needs to ignore, for example, the object that the raycast originates from, the active user if part of a tool, or only the local user of a raycast originating from all users locally.
The <code>Filter</code> field is much more flexible. It takes a [https://learn.microsoft.com/en-us/dotnet/api/system.func-2 <code>System.Func&lt;ICollider, bool&gt;</code>] where <code>ICollider</code> is the potentially hit collider, and <code>bool</code> is the return value of the function. If the bool is true, the raycast will consider the collider hit. Else, the raycast will ignore the collider.
As of the time of writing, the <code>Filter</code> field is unable to be directly controlled by users with custom functions. There currently exists one singular function, <code>FilterUsers</code>, that is able to be put in this field. This function can be retrieved by using a [[meter tool]] set to <code>Perpendicular</code>, inspecting the resulting point, and grabbing the function off the resulting RaycastDriver. This function filters out every single user in the session from being hit by the raycast, which can be useful in specific cases.


<!--T:4-->
<!--T:4-->
== Examples ==
== Examples ==
Can be used to place objects onto a floor, or as a laser pointer, or as part of a draw on a surface pen.
Can be used to place objects onto a floor, or as a laser pointer, or as part of a draw on a surface pen.


<!--T:5-->
<!--T:5-->
== Related Components ==
== See Also ==
* The lighter version, [[Component:RayDriver|Ray Driver Component]]
 
* The lighter version, [[Component:RayDriver|RayDriver]]
* [[ProtoFlux:Raycaster]]
* [[ProtoFlux:Raycast One]]
 
</translate>
</translate>
[[Category:Components{{#translation:}}|Raycast Driver]]
[[Category:Components{{#translation:}}|Raycast Driver]]
[[Category:Components:Transform:Drivers{{#translation:}}|Raycast Driver]]
[[Category:Components:Transform:Drivers{{#translation:}}|Raycast Driver]]

Latest revision as of 06:04, 17 March 2025

Component image 
RaycastDriver component as seen in the Scene Inspector


The RaycastDriver component drives the position of the Slot it is attached to to the location of the hit point of a raycast and aligns its rotation to the normal of the hit object.

Fields

Fields
Name Type Description
persistent Bool Determines whether or not this item will be saved to the server.
UpdateOrder Int Controls the order in which this component is updated.
Enabled Bool Controls whether or not this component is enabled. Some components stop their functionality when this field is disabled, but some don't.
IgnoreHierarchy Slot a hiearchy of slots which to ignore the colliders for
FilterDistance Float ignore hit detections before this distance.
Origin Slot The slot to start the raycast from.
Offset Float3 The offset from Origin before starting the raycast.
Direction Float3 The direction in Origin's local space to shoot in.
MaxDistance Float The maximum distance to raycast for.
NoHitDistance Float How far to raycast shoot for in meters till reporting no hit.
Filter delegate of identity Func`2<ICollider, Bool> A sync delegate that takes a collider and returns a bool. if a collider returns false from this sync delegate, it is ignored when raycasting for objects.
_positionDrive field drive of Float3 The position field to drive. This does not actually affect the field that is driven, but if it is not filled, the component will not function.
_rotationDrive field drive of FloatQ The rotation field to drive. This does not actually affect the field that is driven, but if it is not filled, the rotation of the slot is not changed. Aligns itself to the normal of the surface this raycast hit, or (0,0,0).

Usage

When placed on a slot, _positionDrive and _rotationDrive are automatically filled to the slot's position and rotation. These fields are not actually effective, as this component always writes to the position/rotation of the slot it is on. However, if either of these fields are omitted, the respective functionality of the raycast is not performed.

The raycast is constructed in the local coordinate space of Origin, where Offset controls the origin of the ray relative to the origin and Direction controls the direction of the ray relative to the origin.

MaxDistance controls the maximum distance that the raycast will travel. If a raycast is unable to make contact with a collider within this distance, the position of the slot will be set to NoHitDistance in the direction of the raycast. These two distances are in global scale, and are not affected by either the slot's local scale or the scale of the Origin slot.

If the ray hits a collider, the rotation of the slot will be aligned to the normal of the hit point. This rotation can be transformed into the normal vector by using the Get Forward node on the RaycastDriver slot. If the raycast does not hit a collider, the rotation will be set to (0, 0, 0).

Filtering

There are two ways of filtering what colliders the raycast is able to make contact with.

If IgnoreHierarchy is filled, the raycast will ignore all colliders present under the provided hierarchy. This can be useful if one needs to ignore, for example, the object that the raycast originates from, the active user if part of a tool, or only the local user of a raycast originating from all users locally.

The Filter field is much more flexible. It takes a System.Func<ICollider, bool> where ICollider is the potentially hit collider, and bool is the return value of the function. If the bool is true, the raycast will consider the collider hit. Else, the raycast will ignore the collider.

As of the time of writing, the Filter field is unable to be directly controlled by users with custom functions. There currently exists one singular function, FilterUsers, that is able to be put in this field. This function can be retrieved by using a meter tool set to Perpendicular, inspecting the resulting point, and grabbing the function off the resulting RaycastDriver. This function filters out every single user in the session from being hit by the raycast, which can be useful in specific cases.

Examples

Can be used to place objects onto a floor, or as a laser pointer, or as part of a draw on a surface pen.

See Also