0 votes

Hi, I previously asked a question similar to this here.

I want the randomiser to choose a number, 1 or 2. If it lands on 0, then the barrel follows the first Path2D route, else if lands on 1 (in this instance) it doesn't do anything. I've created a timer so this randomisation occurs every 10 seconds.

Here is my code so far, it might be messed up slightly as I've been trying various different things to make it work.

extends Node

var rndvalue = null

func _ready():
    set_process_input(true)
    set_fixed_process(true)
    get_node("Background Music").play()
    randomize()
    #self.get_node("../Lives Amount Label").player_lives

func show_PausePanel():
    get_node("PausePanel").show()
    get_node("DarkenBackground").show()
    get_node("Background Music").stop()
    get_tree().set_pause(true)
    #if (Input.is_action_pressed(get_node("../PausePanel/Exit Game"))):
        #get_tree().quit()
    #return

func hide_PausePanel():
    get_node("PausePanel").hide()
    get_node("DarkenBackground").hide()
    get_node("Background Music").play()
    get_tree().set_pause(false)
    #get_node("../Player/Mario").add_exception(true)
    return

func _input(event):
    if(Input.is_key_pressed(KEY_ESCAPE)) and get_node("PausePanel").is_hidden():
        show_PausePanel()

    elif(Input.is_key_pressed(KEY_ESCAPE)) and get_node("PausePanel").is_visible():
        hide_PausePanel()

func _on_BarrelSpawnTimer_timeout(delta):
    rndvalue = randi() % 2
    var barrelFollow = get_node("BarrelPaths/BarrelPath/BarrelFollowPath")
    if rndvalue == 0:
        print("Path2D is turned on!")
        barrelFollow.set_offset(barrelFollow.get_offset()+(100 * delta))
    else:
        print("Path2D is turned off!")
        #start another Path2D, I haven't got around to this yet as I want to make sure what I have works first.

I cannot figure out how to get the Barrel to follow the path I've laid out if the random number lands on 0. Apparently you cannot use delta in the timeout() function.

Previously I was able to make the Barrel follow the path using this code:

func _fixed_process(delta):
    var barrelFollow = get_node("../BarrelPaths/BarrelPath/BarrelFollowPath")
    barrelFollow.set_offset(barrelFollow.get_offset()+(100* delta))

But that was before all of the timer and randomise stuff. The code above would just make the barrel follow that path from the start of the game, which is not what I want.

If anyone would be able to help me figure this out, I would be immensely thankful!

in Engine by (89 points)

Look at this tutorial

http://www.godotengine.de/en/tutorials/create_a_path_and_follow_it

perhaps you find a solution

Thanks for the link, unfortunately I didn't find a solution. Instead of doing by randomisation I'll have to use something much simpler, seen as I cannot figure out how to do it.

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 Frequently asked questions and 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 [email protected] with your username.