RaycastResult
A userdata object representing a raycast result.
A raycast result is a collection of data received from a raycast. The result contains information about where the raycast travelled and what objects it eventually hit.
Raycast results are the result of functions such as sm.physics.raycast, sm.physics.distanceRaycast and sm.localPlayer.getRaycast.
Values:
-
directionWorld[ Vec3 ]Get: The directional vector of the raycast, with length equal to the range the raycast was created with.
-
Get: Returns the fraction (0–1) of the distance reached until collision divided by the ray's length.
-
normalLocal[ Vec3 ]Get: Returns the normal vector of the surface that was hit, relative to the target's rotation.
-
normalWorld[ Vec3 ]Get: Returns the normal vector of the hit surface
-
originWorld[ Vec3 ]Get: Returns the starting world position of the raycast.
-
pointLocal[ Vec3 ]Get: Returns the world position of the point that was hit, relative to the target's position.
-
pointWorld[ Vec3 ]Get: Returns the world position of the point that was hit.
-
Get: Returns the physics type of the target that was hit. (See sm.physics.types)
-
Get: Returns whether the raycast successfully hit a target.
Functions
getAreaTrigger
raycastResult:getAreaTrigger( )
Returns the AreaTrigger hit during the raycast. This is only possible if RaycastResult.type is equal to "areaTrigger", otherwise this will return nil.
Parameters:
| Name | Type | Description |
|---|---|---|
raycastResult |
RaycastResult | The raycast result. |
Returns:
| Type | Description |
|---|---|
| AreaTrigger | The areaTrigger target. |
getBody
raycastResult:getBody( )
Returns the Body hit during the raycast. This is only possible if RaycastResult.type is equal to "body", otherwise this will return nil.
Parameters:
| Name | Type | Description |
|---|---|---|
raycastResult |
RaycastResult | The raycast result. |
Returns:
| Type | Description |
|---|---|
| Body | The body target. |
getCharacter
raycastResult:getCharacter( )
Returns the Character hit during the raycast. This is only possible if RaycastResult.type is equal to "character", otherwise this will return nil.
Parameters:
| Name | Type | Description |
|---|---|---|
raycastResult |
RaycastResult | The raycast result. |
Returns:
| Type | Description |
|---|---|
| Character | The character target. |
getHarvestable
raycastResult:getHarvestable( )
Returns the Harvestable hit during the raycast. This is only possible if RaycastResult.type is equal to "harvestable", otherwise this will return nil.
Parameters:
| Name | Type | Description |
|---|---|---|
raycastResult |
RaycastResult | The raycast result. |
Returns:
| Type | Description |
|---|---|
| Harvestable | The harvestable target. |
getJoint
raycastResult:getJoint( )
Returns the Joint hit during the raycast. This is only possible if RaycastResult.type is equal to "joint", otherwise this will return nil.
Parameters:
| Name | Type | Description |
|---|---|---|
raycastResult |
RaycastResult | The raycast result. |
Returns:
| Type | Description |
|---|---|
| Joint | The joint target. |
getLiftData
raycastResult:getLiftData( )
Returns the Lift hit during the raycast. This is only possible if RaycastResult.type is equal to "lift", otherwise this will return nil.
Parameters:
| Name | Type | Description |
|---|---|---|
raycastResult |
RaycastResult | The raycast result. |
Returns:
| Type | Description |
|---|---|
| Lift | The lift |
| boolean | True if the lift is top |
getShape
raycastResult:getShape( )
Returns the Shape hit during the raycast. This is only possible if RaycastResult.type is equal to "body", otherwise this will return nil.
Parameters:
| Name | Type | Description |
|---|---|---|
raycastResult |
RaycastResult | The raycast result. |
Returns:
| Type | Description |
|---|---|
| Shape | The shape target. |
getTerrainAssetMaterialName
raycastResult:getTerrainAssetMaterialName( )
Returns the material hit during the raycast. This is only possible if RaycastResult.type is equal to "terrainAsset", otherwise this will return empty.
Parameters:
| Name | Type | Description |
|---|---|---|
raycastResult |
RaycastResult | The raycast result. |
Returns:
| Type | Description |
|---|---|
| string | The material name. |