RayCastHit
ClassHit results of a ray-cast provided to script.
- Available on all platforms
Since Lens Scripting v164
Hit results of a ray-cast provided to script. See Probe.
Index
Example
// Given an object with a BodyComponent
// If the object intersects with the ray described
// by rayStart and rayEnd, print a message.
var rayStart = new vec3(0.0, -100.0, 0.0);
var rayEnd = new vec3(0.0, 100.0, 0.0);
// Create a probe to raycast through all worlds.
var globalProbe = Physics.createGlobalProbe();
globalProbe.rayCast(rayStart, rayEnd, function (hit) {
if (hit) {
print("Raycast hit: " + hit.collider.getSceneObject().name);
}
});
// Create a probe to raycast through only the implicit root world.
var rootProbe = Physics.createRootProbe();
rootProbe.rayCast(rayStart, rayEnd, function (hit) {
if (hit) {
print("Raycast hit all: " + hit.collider.getSceneObject().name);
}
});
// On Tap, raycast through the scene at the tapped position and print out a message for each object hit.
// @input Component.Camera camera
var cameraTransform = script.camera.getTransform();
var camera = script.camera;
script.createEvent("TapEvent").bind(function(touchArgs) {
var touchPos = touchArgs.getTapPosition();
var nearPos = camera.screenSpaceToWorldSpace(touchPos, 0);
var farPos = camera.screenSpaceToWorldSpace(touchPos, camera.far - camera.near);
Physics.createGlobalProbe().rayCastAll(nearPos, farPos, function(hitResults) {
print("Hit " + hitResults.length + " objects:")
for(var i=0; i<hitResults.length; i++) {
var hit = hitResults[i];
print(hit.collider.getSceneObject().name + " at " + hit.position);
}
});
});
Extends
Properties
collider
readonlycollider:ColliderComponent
The collider that was hit.
Since
Lens Scripting Version 164
distance
readonlydistance:number
Distance from the ray origin to the point of intersection.
Since
Lens Scripting Version 164
normal
readonlynormal:vec3
Surface normal on the collider at the point of intersection.
Since
Lens Scripting Version 164
position
readonlyposition:vec3
Position at the point of intersection.
Since
Lens Scripting Version 164
skipRemaining
skipRemaining:
boolean
Set to true to skip remaining results, if any.
Since
Lens Scripting Version 164
Default Value
false
t
readonlyt:number
Ray interpolant at the point of intersection, in the range [0, 1].
Since
Lens Scripting Version 164
triangle
readonlytriangle:TriangleHit
The hit triangle, if it exists. This is set on intersection with mesh-based colliders, and null otherwise.
Since
Lens Scripting Version 181
Methods
getTypeName()
staticgetTypeName():TypeName<RayCastHit>
Returns the fully-qualified JavaScript type name for this class (for example, "Component.Camera"). This is a static accessor (no instance required) and returns the same value as the instance getTypeName().
Returns
TypeName<RayCastHit>
Since
Lens Scripting Version 164
Overrides
getTypeName()
getTypeName():
string
Returns the name of this object's type.
Returns
string
Inherited from
isOfType()
isOfType(
type):boolean
Returns true if the object matches or derives from the passed in type.
Parameters
| Parameter | Type |
|---|---|
type | string |
Returns
boolean
Inherited from
isSame()
isSame(
other):boolean
Returns true if this object is the same as other. Useful for checking if two references point to the same thing.
Parameters
| Parameter | Type |
|---|---|
other | ScriptObject |
Returns
boolean