Lengthen a Raycast2d in script?

Godot Version

4.3

Question

so this is my question, i want to lengthen the raycast2d in my game using script, and my player structure is something like this,

player(characterbody2d)
|_node2d
|_raycast1
|_raycast2
|_raycast3

added a node2d as a parent for the raycast, I want to create a method inside the player script to be called in another script to lengthen those raycast, (something like a skill upgrade that will lengthen the raycast by a specific amount) is it doable?

sure. Something like this should do it:

for child in $Node2D.get_children():
    if child is Raycast2D:
        child.target_position = # put your new target_position here

wait, so the raycsst will be moved? not lengthen?

no its the position the raycast is looking at, which also defines its length

Thank you.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.