game development - How can I solve the virtual line problem I created with RayCast2D? - Stack Overflow

I want to make a Bubble Shooter style work with Godot Engine 4.3 and I need to draw a virtual line duri

I want to make a Bubble Shooter style work with Godot Engine 4.3 and I need to draw a virtual line during launch. First, I created the RayCast2D node and added 2 Line2Ds as “LineOne and LineTwo” as its child nodes. Then, when I targeted this virtual line to objects, I wanted the objects to get the color I assigned to their IDs. Now the things I targeted with the code I gave below are working correctly, but the virtual line “LineTwo” is working, but this code cannot get the color of the targeted object with “dl.default_color = get_collider().color” and also “dl.points[1].x = vector_line_length” with this code, the virtual line does not end after reaching the targeted object. These two lines of code are not working in my project. How can I solve this correctly? Thank you for your help.

My Codes:

extends RayCast2D
@onready var vl = $LineOne
@onready var dl = $LineTwo
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 $"../Shoot”.was_shooted:

        vl.visible = true
        dl.visible = true

        if $"../Shoot”.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())
                vl.default_color = default_color
                dl.default_color = default_color
                vl.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:
                    vl.default_color = get_collider().color
                    dl.default_color = get_collider().color
                else:
                    vl.default_color = default_color
                    dl.default_color = default_color
                vl.points[1].x = collision_point.x
                dl.visible = false
        else:
            vl.default_color = default_color
            vl.points[1].x = vector_line_length
            dl.points[1].x = vector_line_length
            
    else:
        vl.visible = false
        dl.visible = false

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1742345789a4426516.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信