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!