@7892 said:
Thanks for your help! There are 2 or 3 typo errors but after correcting them it still does not work :(
Probable me doing something wrong...
RayCast2D (script)
-Line2D_One (pos 0,0)
-Line2D_Two (pos 0,0)
Hmm, maybe or maybe I wrote it wrong. I do not know right off, I would have to test. How does it not work?
Btw how does this handle multi bounce? I dont understand how the script works :(
I will try to explain, though I realized I could have done it differently since then (ah well):
The system uses two Line2D nodes to represent the raycast. The first Line2D node represents the origin of the Raycast. If the raycast detects no collision, then this line just draws from the origin to the length of the ray in the direction the raycast points to.
If there is a collision, then the first Line2D node will draw the line starting from the raycast origin and ending at the raycast collision point. That is all that the first Line2D does in the code.
The second Line2D is a little different. If there is no collision on the Raycast, then it just becomes invisible. If there is a collision, then the second Line2D draws the line starting at the raycast collision point (where the first line left off). The ending position of the second Line2D is based on the normal (the "bounce") of the raycast. The normal just returns the direction, so we calculate the length of the second Line2D by getting the difference of the first Line2D and the Raycast's total length. This tells us how far the second Line2D needs to go.
Now, in hindsight, I realized one Line2D node could be used for this. For some reason, I forgot that a Line2D node can have more than two points, not sure why I forgot that. This means the code could be simplified to use just a single Line2D. The code is mostly the same though.