Raycast: Difference between revisions
-u ndefined- (talk | contribs) (Add infobox; change port documentation, wording and formatting) |
(→Examples: Fixed spelling mistake) |
||
(2 intermediate revisions by the same user not shown) | |||
Line 18: | Line 18: | ||
== Notes == | == Notes == | ||
* A Raycast can only detect when the line hits the outside surface of a block. If the line starts ''inside'' the block then it will not hit that block when going out. | * A Raycast can only detect when the line hits the outside surface of a block. If the line starts ''inside'' the block then it will not hit that block when going out. | ||
* Raycast won't detect an object that has been [[Create Object|created]] in the same frame. You have to wait 1 frame after creating an object for Raycast to detect it. | |||
* It cannot detect blocks with no [[Collider|collision]]. | * It cannot detect blocks with no [[Collider|collision]]. | ||
Line 25: | Line 27: | ||
In edit mode, a visible line will be drawn between the start and end points: green if there is not a hit, red otherwise. | In edit mode, a visible line will be drawn between the start and end points: green if there is not a hit, red otherwise. | ||
This effect can be used to make red and green line drawings, but it won't be visible in play mode unless the level contains only | This effect can be used to make red and green line drawings, but it won't be visible in play mode unless the level contains only script blocks and no normal blocks. | ||
Because red lines require that the raycast hits the floor or a block with collision, if intersection with a floor is not an option, you must use a loophole to get regular blocks to appear in play mode. | Because red lines require that the raycast hits the floor or a block with collision, if intersection with a floor is not an option, you must use a loophole to get regular blocks to appear in play mode. | ||
If a normal block is ''inside'' a | If a normal block is ''inside'' a script block at the start of the level, it will not trigger the hiding of script blocks and Raycast lines. | ||
On the first frame the normal block can then be moved to the floor, and set to visible (being inside a | On the first frame the normal block can then be moved to the floor, and set to visible (being inside a script block makes it start not visible). | ||
Then set it in the path of a Raycast line to turn it red. | |||
== Examples == | |||
Cast a ray in the direction an object is facing. | |||
The <code>{{Port|v|0,0,1}}</code> indicates the object points in the positive Z axis by default, and the raycast length is 1. | |||
{{Image|Raycast example1.png}} | |||
[[Category:Blocks]] | [[Category:Blocks]] |
Latest revision as of 02:21, 6 August 2024
Type | Script block |
Collider | None |
Folder | Objects |
Ports | |
---|---|
Inputs | From To |
Outputs | Hit? Hit Pos Hit Obj |
Traces a line between two points and outputs the following correspondingly:
- True if it hits an object.
- The point where the object is detected, or
0, 0, 0
otherwise. - The object that was hit, or
None
if none is detected or the ground is hit.
Notes
- A Raycast can only detect when the line hits the outside surface of a block. If the line starts inside the block then it will not hit that block when going out.
- Raycast won't detect an object that has been created in the same frame. You have to wait 1 frame after creating an object for Raycast to detect it.
- It cannot detect blocks with no collision.
Raycast drawing
In edit mode, a visible line will be drawn between the start and end points: green if there is not a hit, red otherwise. This effect can be used to make red and green line drawings, but it won't be visible in play mode unless the level contains only script blocks and no normal blocks.
Because red lines require that the raycast hits the floor or a block with collision, if intersection with a floor is not an option, you must use a loophole to get regular blocks to appear in play mode. If a normal block is inside a script block at the start of the level, it will not trigger the hiding of script blocks and Raycast lines. On the first frame the normal block can then be moved to the floor, and set to visible (being inside a script block makes it start not visible). Then set it in the path of a Raycast line to turn it red.
Examples
Cast a ray in the direction an object is facing.
The 0,0,1
indicates the object points in the positive Z axis by default, and the raycast length is 1.
