// Perform a ray cast from the controller position in the forward direction
val hitInfo = scene.lineSegmentIntersect(
dataModel,
controllerPosition,
controllerPosition + (controllerForward * maxDistance)
)
// Check if something was hit
if (hitInfo != null) {
// Access hit information
val hitEntity = hitInfo.entity
val hitPoint = hitInfo.point
val hitNormal = hitInfo.normal
val hitDistance = hitInfo.distance
// Perform actions based on the hit
if (hitEntity != null) {
// Interact with the hit entity
}
}
class HitInfo(val entity: Entity?, val sceneObjectHandle: Long, val nodeId: Int, val meshElementId: Int, val distance: Float, val point: Vector3, val normal: Vector3, val textureCoordinate: Vector2)
HitInfo
(
entity
, sceneObjectHandle
, nodeId
, meshElementId
, distance
, point
, normal
, textureCoordinate
)
|
Signature
constructor(entity: Entity?, sceneObjectHandle: Long, nodeId: Int, meshElementId: Int, distance: Float, point: Vector3, normal: Vector3, textureCoordinate: Vector2) Parameters
sceneObjectHandle:
Long
nodeId:
Int
meshElementId:
Int
distance:
Float
Returns |
distance
: Float
[Get] |
The distance from the interactor (controller, etc.) to the hit point
Signature
val distance: Float |
entity
: Entity?
[Get] |
The entity that was hit, or null if no entity is associated with the SceneObject
Signature
val entity: Entity? |
meshElementId
: Int
[Get] |
The ID of the mesh element (e.g., triangle) that was hit
Signature
val meshElementId: Int |
nodeId
: Int
[Get] |
The ID of the node in the SceneObject that was hit
Signature
val nodeId: Int |
normal
: Vector3
[Get] |
The surface normal at the hit point in world space
Signature
val normal: Vector3 |
point
: Vector3
[Get] |
The 3D position of the hit point in world space
Signature
val point: Vector3 |
sceneObjectHandle
: Long
[Get] |
The handle of the SceneObject that was hit
Signature
val sceneObjectHandle: Long |
textureCoordinate
: Vector2
[Get] |
The UV texture coordinate at the hit point
Signature
val textureCoordinate: Vector2 |