codernesim I did not write any code for Raycast

Who wrote the raycast code?

codernesim Also how can I see it in the debug section?

Debug -> Visible collision shapes.

    xyz
    I have only this code about Raycast.
    The screenshots you mentioned are as follows.


      codernesim Well there you have it. There is no cast ray (red line) aligned with your second line. You need to position and rotate the raycast node so that its ray coincides with the line.

        xyz
        That's how it works on the stage.
        Is there anything wrong here?
        Also, if I need to position it, where can I do it, with code or on the stage?

        • xyz replied to this.

          codernesim You need to do it via code because the position/orientation of the second raycast depends on the rayhit result of the first raycast.

            xyz
            I understood what you wanted to say and learned more about the cause of the error.
            So how can I solve this in the first codes I gave?
            Do you have any idea?

            • xyz replied to this.

              codernesim Start by using only 2 ray cast nodes. If one collides with a wall, set other's origin to its collision point and its look vector to the look vector of the first raycast reflected around the hit normal. Best to operate in global space to avoid local coordinate system confusion.

                xyz
                I set the Raycast2Ds as you said and the second Raycast is now active and the second Raycast is now visible and working the way I want it to.
                But the problem here is that now the SecondLine color added to the second Raycast is not the same as the first one.
                I think the second Raycast does not have the properties of the first Raycast.
                How can I fix this, my code is below.

                extends RayCast2D
                
                @onready var vl = $FirstRay
                @onready var dl = $SecondRay
                @onready var one = $FirstRay/FirstLine
                @onready var two = $SecondRay/SecondLine
                var vector_line_length = 600
                @onready var manager = $"../Manager"
                var default_color: Color = Color(0.388,0.643,0.969,1)
                
                func _physics_process(_delta: float) -> void:
                	
                	if not $"../Control3".was_shooted or not $"../Control4".was_shooted or not $"../Control5".was_shooted:
                
                		vl.visible = true
                		dl.visible = true
                
                		if $"../Control3".can_be_shot or $"../Control4".can_be_shot or $"../Control5".can_be_shot:
                			look_at(get_global_mouse_position())
                
                		if is_colliding():
                			if not manager.items.has(get_collider()):
                				var collision_point = to_local(get_collision_point())
                				
                				one.default_color = default_color
                				two.default_color = default_color
                				one.points[1].x = collision_point.x
                	
                				dl.position = collision_point
                				dl.rotation_degrees = (rotation_degrees * 2) * -1
                				dl.visible = true
                			else:
                				var collision_point = to_local(get_collision_point())
                				if get_collider().color != null:
                					one.default_color = get_collider().color
                					two.default_color = get_collider().color
                					
                					
                				else:
                					one.default_color = default_color
                					two.default_color = default_color
                				one.points[1].x = collision_point.x
                				dl.visible = false
                		else:
                			
                			one.default_color = default_color
                			one.points[1].x = vector_line_length
                			dl.visible = false
                	else:
                		vl.visible = false
                		dl.visible = false


                • xyz replied to this.

                  xyz
                  Is it possible to provide this collision with code?
                  If possible, how should I do it?
                  Thanks for your help.

                  • xyz replied to this.

                    xyz
                    I did as you said and it was fixed in a few transactions.
                    Now it works the way I want it to.
                    Thank you for your help.