Hi, new to Godot. My first game is a simple mobile game where the player is an apple falling out of a tree and has to dodge branches to reach the bottom. There are 3 different sized branches small medium and large. I have a branch coming up the screen and when it gets off-screen a collision is scripted to queue_free the branch and spawn a new one in the same starting position. It works great but now I need to figure out how to make that branch spawn as either a large, medium, or small branch randomly. All the tutorials or forum posts I found were just dealing with spawning in a random position. I need it to spawn in a constant position but a random sprite. That made sense. Thank you.

Here's the code for the collision that deletes and spawns a new sprite if that helps:

`extends Area2D

var Wall = preload("res://branch_large.tscn")

func respawn():
var Wall_instance = Wall.instantiate()
Wall_instance.position = Vector2(0,1472)
get_parent().call_deferred("add_child",Wall_instance)

func _on_area_2d_body_entered(body):
if body.name == "branchLarge":
body.queue_free()
await get_tree().create_timer(1).timeout
respawn()
`

    LamplightCreativeStudio Put preloaded packed scenes into an array. When spawning, pick one at random from the array using Array::pick_random() and instantiate it.

    LamplightCreativeStudio

    • Preload your three different branch scenes, like you did for the large one.
    • Add all three to an array.
    • When respawning pick a random element of that array and instantiate() it.

    Note that your if body.name == "branchLarge": statement won't work anymore so you need a different way to handle this.