
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
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
- The lighter version, RayDriver
- ProtoFlux:Raycaster
- ProtoFlux:Raycast One