Scripting

Search The Documentation:

  1. Home
  2. Docs
  3. Scripting
  4. Collision
  5. Raycast

Raycast

Platform Compatibility

PC Mac OSX Oculus Quest
X X X

Perform a raycast and get the stored object number back, optionally store the hit position if the raycast hits something. Returns -1 if nothing is hit by the raycast.

Think of a raycast as a laser beam that reports the first object it collides with. Will not collide with the object using a raycast itself.

Parameters:

  • start
    • A string value for X,Y,Z position
  • direction
    • A string value for X,Y,Z Euler rotation
  • maxDistance Optional
    • A float value, if distance is less or equal to 0 then infinite distance is assumed
  • layers Optional
  • hitTriggers Optional
    • A boolean value
  • storeHitPos Optional
    • A string value representing the dictionary string to store to, retrieve X,Y,Z with obj.getDictString()

returns an Integer (whole number) value

Example:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
start = obj.getPos(obj.self())
direction = obj.getForward(obj.self())
maxDistance = 10
layers = ""
hitTriggers = false
storeHitPos = "RayHitPos"

hitObj = obj.Raycast(start, direction, maxDistance, layers, hitTriggers, storeHitPos)

--Alternate raycast format skipping max distance
hitObj = obj.Raycast(start, direction, layers, hitTriggers, storeHitPos)

--Alternate raycast format skipping max distance and layers
hitObj = obj.Raycast(start, direction, hitTriggers, storeHitPos)

--Alternate raycast format that only hits colliders and stores the position of the hit
hitObj = obj.Raycast(start, direction, storeHitPos)

--Shortest raycast format that only hits colliders
hitObj = obj.Raycast(start, direction)

if hitObj > -1 then
   obj.set3DText(obj.getStoredName(hitObj) .. " hit at " .. obj.getDictString(storeHitPos))
end
Tags
Was this article helpful to you? Yes No

How can we help?