Raycast: Difference between revisions

181 bytes removed ,  21 May 2024
Add infobox; change port documentation, wording and formatting
(Created page with "File:Raycast1.png Traces a line between two points and outputs True if the line hits anything, the position of intersection, and the object it hit. (Think of it as a laser, you stand in the starting position and shoot a laser to the end position.) Inputs: * From: the start of the line. * To: the end of the line. Outputs: * Hit?: Returns whether the line hits an object. * Hit Pos: The point where the object is detected, or [0, 0, 0] if it...")
 
(Add infobox; change port documentation, wording and formatting)
Line 1: Line 1:
[[File:Raycast1.png]]
{{Block
|image=Raycast.png
|type=s
|folder=Objects
|input1={{Port|v|From}}
|input2={{Port|v|To}}
|output1={{Port|t|Hit?}}
|output2={{Port|v|Hit Pos}}
|output3={{Port|o|Hit Obj}}
}}


Traces a line between two points and outputs [[Truth (True & False)|True]] if the line hits anything, the position of intersection, and the object it hit. (Think of it as a laser, you stand in the starting position and shoot a laser to the end position.)
Traces a line between two points and outputs the following correspondingly:


Inputs:
* [[Truth (True & False)|True]] if it hits an object.
 
* The point where the object is detected, or <code>0, 0, 0</code> otherwise.
* From: the start of the line.
* The object that was hit, or <code>None</code> if none is detected or the ground is hit.
* To: the end of the line.
 
Outputs:
 
* Hit?: Returns whether the line hits an object.
* Hit Pos: The point where the object is detected, or [0, 0, 0] if it doesn't detect an object.
* Hit Obj: The object that was hit, or None if none is detected, or the ground is hit.


== Notes ==
== Notes ==


* Note that Raycast detects 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. Also, it won't  detect an object that has been created in the same frame, you have to wait 1 frame after creating the object for Raycast to detect it.
* 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. Also, it won't  detect an object that has been [[Create Object|created]] in the same frame, you have to wait 1 frame after creating the object for Raycast to detect it.
 
* It cannot detect [[Pass Through]]s and [[Script Block]]s.
 
== 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 scripting blocks and no normal blocks.
* It cannot detect blocks with no [[Collider|collision]].


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 scripting 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 scripting block makes it start not visible). Then set it in the path of a Raycast line to turn it red.
=== Raycast drawing ===


This is used in the game Swingflick by Origedit. Note a game cannot be featured using this.
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 scripting 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 scripting 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 scripting block makes it start not visible). Then set it in the path of a Raycast line to turn it red.


[[Category:Blocks]]
[[Category:Blocks]]