0 votes

Hi,

I have 3 camera scripts with the feat of following the object. But When I change between pretty difference scripts(not very similar ones), it is impossible to define Node Path again.

This one is Interpolated camera:

func _physics_process(_delta):

    target = get_node("../Player").get_path()
#   target = get_node("../Player").get_global_transform().origin
#   var target2 = get_node("../Player/SpringArm2").get_global_transform().origin

    pos = get_global_transform().origin
#   if target:
    var up = Vector3(0,1,0)
    offset = pos - get_node("/root/Node/Player").get_global_transform().origin
    offset = offset.normalized() * Vector3(distance, distance, distance)
    offset.y = height
    height = clamp(height, 4, 10)
    pos = get_node(target).get_global_transform().origin + offset
    look_at_from_position(pos, get_node(target).get_global_transform().origin , Vector3(0,1,0))
    var space_state = get_world().get_direct_space_state()
    var obstacle
    obstacle = space_state.intersect_ray(get_node("/root/Node/Player").get_translation(),  get_translation())
    if not obstacle.empty():
        print(obstacle["collider"])
        look_at_from_position(obstacle.position, get_node("../Player").get_global_transform().origin , Vector3(0,1,0))
    var _look2_1 = 0
    var _look2_2 = 6
    var _look2_3 = float()
    _look2_2 -= height - 10
    _look2_3 -= distance + 40

This one from kidscancode.com. Thanks to him BTW.

> func _process(delta):     if !mouse_control:      get_input_keyboard(delta)
>   $InnerGimbal.rotation.x = clamp($InnerGimbal.rotation.x, -100.4,
> 80.01) #$InnerGimbal.rotation.x = clamp($InnerGimbal.rotation.x, -1.4, -0.01)     rotation.y = clamp(rotation.y, -100.4, 80.01)   scale = lerp(scale, Vector3.ONE * zoom, zoom_speed)
> # target = get_node("../Player").get_path()   if target:      global_transform.origin = get_node(target).global_transform.origin
>       
> # if arrow != null or area != null:   arrow = get_parent().find_node("Arrow")     arrow.global_transform.basis =
> arrow.global_transform.looking_at(get_node("/root/Node/Area").global_transform.origin,Vector3(0,1,0)).basis   arrow.scale = Vector3(arrow_scale, arrow_scale, arrow_scale)
>   get_node("/root/Node_PauseMenu").get_node("RichTextLabel").text =
> String(Engine.get_frames_per_second())
in Engine by (193 points)

Ok. I get it now. I need to free the previous script but how will I call that script again. It says freed object can not be called again:

Shortly:

            get_node("/root/Node/CameraGimbal").get_script().free()
            get_node("LabelForValues").text = "Camera" + String(number)
            get_node("/root/Node/CameraGimbal").set_script(load(dict[number]

Longly:)

func _input(event):
    if Input.is_action_just_pressed("ui_c"):
        if name == "Camera":
            print(get_node("/root/Node/CameraGimbal").target, "TARGET")
            if number < dict.size():
                number += 1

                get_node("LabelForValues").text = "Camera" + String(number)
                get_node("/root/Node/CameraGimbal").target = "../Player"
                get_node("/root/Node/CameraGimbal").set_script(load(dict[number][1]))
#               get_node("/root/Node/CameraGimbal").script = load(dict[number][1])
#               get_node("/root/Node/CameraGimbal").target = get_viewport().get_node("Node/Player").get_path()
                Global_batch.camera_id += 1
                print("number ", number, " dict ", dict[number][1]," id : ", Global_batch.camera_id, " target ", get_node("/root/Node/CameraGimbal").target)
#               get_node("/root/Node/CameraGimbal").call_deferred("you")
#               get_node("/root/Node/CameraGimbal").call_deferred("_ready")
                get_node("/root/Node/CameraGimbal").target = get_node("/root/Node/Player").get_path()

                return
            if number <= dict.size():
                number -= 1
                get_node("/root/Node/CameraGimbal").get_script().free()
                get_node("LabelForValues").text = "Camera" + String(number)
                get_node("/root/Node/CameraGimbal").set_script(load(dict[number][1]))
#               get_node("/root/Node/CameraGimbal").script = load(dict[number][1]
                Global_batch.camera_id -= 1
#               get_node("/root/Node/CameraGimbal").call_deferred("you")
#               get_node("/root/Node/CameraGimbal").call_deferred("_ready")
#               get_node("/root/Node/CameraGimbal").target = "../Player"
                get_node("/root/Node/CameraGimbal").target = get_viewport().get_node("Node/Box").get_path()
                print("number ", number, " dict ", dict[number][1]," id : ", Global_batch.camera_id, " target ", get_node("/root/Node/CameraGimbal").target)

                return

Turn out that free() not works with scripts because it is not a node but a reference. How do we free or clear or delete references and still call them back!?

Please log in or register to answer this question.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.