0 votes

In the game I'm developing, I'm instancing a tilemap repeatedly, to make an endless runner. Each tilemap has their own Area2D node, which when spawned in, should instance a random obstacle. The issue here, is that the obstacles instance at the first Area2D that was spawned, when the game was started. is there any way to get them to spawn at their own Area2D? I'm still pretty new to this, and I'm not seeing the issue.

Godot version 3.4.2
in Engine by (103 points)

Could you please share the code that's instancing objects?

Instancing TileMap:

func _process(delta):
if spawnpos.distance_to(player.global_position) < 300:
    spawn_ground()
func spawn_ground():
var spawnblock = prebuild1.instance()
add_child(spawnblock)
spawnblock.spawn()
spawnblock.global_position.x = spawnpos.x
spawnpos.x = spawnpos.x + groundwidth

Instancing Obstacles:

func spawn():
randomize()
var conespawn = cone.instance()
conespawn.position.x = $Area2D.global_position.x + lerp(-50, 50, randf())
conespawn.position.y = $Area2D.global_position.y
get_parent().get_parent().add_child(conespawn)

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 webmaster@godotengine.org with your username.