0 votes

Hi All.
I have a bunch of area nodes placed at different distances from the player - I want to use them to measure the length of a throw of a rigid body by the player. Basically, the length would be measured by area nodes emitting signals to a 'measurement' function once the rigid body hits the ground in their area (ie, enters them).

I want to only build one function to collect the lengths and display them, therefore I am thinking of passing a length value from each area node into the display function's length variable. Something like this:

Area node's code:

extends Area

onready var thrownObject = get_node(“root/thrownObject")

func _ready():
    connect("body_entered", thrownObject, “measure_length.length_variable = 1000”) 

Display function's code:

func measure_length():

 var length_variable
    if body.name == “thrownObject”
        print(“Object landed on 1000”)

Or something along these lines. What would be the best method to achieve this?

asked Jan 14 in Engine by Macryc (44 points)

1 Answer

+1 vote

Send a signal to the script that holds the length var . The body enters the area, then the area sends a signal to the script with the var and tells that script to change the var to the new length and print it.

Or you can use a singleton which can hold a global var. A little bit more advance but cleaner than the other option http://docs.godotengine.org/en/stable/getting_started/step_by_step/singletons_autoload.html

answered Jan 15 by Asthmar (80 points)
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.