The Godot Q&A is currently undergoing maintenance!

Your ability to ask and answer questions is temporarily disabled. You can browse existing threads in read-only mode.

We are working on bringing this community platform back to its full functionality, stay tuned for updates. | Twitter

0 votes

I'm following the tutorial on dodge the creeps, and unable to make mobs spawn randomly on the PathFollow2D - looks like the position that is being returned by the PathFollow2D is the one set in the editor > MobPath > Node > Node2D > Transform > Position (changing it here makes creeps spawn at this location instead of the top left corner). Regardless of the offset or even the shape of the curve (see screenshot), mobs spawn only at (0, 0)


extends Node const Player = preload("res://scenes/player/")
const Mob = preload("res://scenes/mob/") export var mob_scene: PackedScene
var score: int func setupmobgeneration() -> void:
randomize() func get_player() -> Player:
return $Player as Player func getscoretimer() -> Timer:
return $ScoreTimer as Timer func getstarttimer() -> Timer:
return $StartTimer as Timer func getmobtimer() -> Timer:
return $MobTimer as Timer func getstartingposition() -> Position2D:
return $StartingPosition as Position2D func getmobspawn_location() -> PathFollow2D:
return $MobPath/MobSpawnLocation as PathFollow2D func ready() -> void:
mob_generation() func gameover() -> void:
score_timer().stop() func newgame() -> void:
score = 0
getstarttimer().start() func spawnmobalongpath() -> void:
var mob: Mob = mob
# choose a random point along the spawn path
var spawnlocation = getmobspawnlocation()
spawnlocation.offset = randi()
debug("Sampled spawn location:", spawnlocation.position)
# Rotate 90 degrees + some randomness +- 45
var mob
direction = spawnlocation.rotation + PI / 2
direction += randrange(-PI/4, PI/4)
# Pick mob velocity
var speed = rand
range(150.0, 250.0)
var velocity = Vector2(speed, 0).rotated(mobdirection)
# Apply generated values
mob.position = spawn
mob.rotation = mobdirection
velocity = velocity
debug("Spawned a mob at", mob.position, "with velocity", velocity) func onMobTimertimeout():
mobalongpath() func onScoreTimer_timeout() -> void:
score += 1 func onStartTimertimeout():

Example logs from running this scene:

Godot Engine v3.4.4.stable.official.419e713a2 -
OpenGL ES 2.0 Renderer: AMD RENOIR (DRM 3.44.0, 5.17.9-051709-generic, LLVM 12.0.0)
OpenGL ES Batching: ON Sampled spawn location:(0, 0)
At: res://scenes/main/
Spawned a mob at(0, 0)with velocity(80.529663, 127.630013)
At: res://scenes/main/
Sampled spawn location:(0, 0)
At: res://scenes/main/
Spawned a mob at(0, 0)with velocity(105.036392, 113.644714)
At: res://scenes/main/
Sampled spawn location:(0, 0)
At: res://scenes/main/
Spawned a mob at(0, 0)with velocity(-159.286285, 165.168213)
At: res://scenes/main/

Here is the Path2D in editor:
enter image description here

Here is the Main scene tree structure:
enter image description here

Godot version v3.4.4.stable.official [419e713a2]
in Engine by (12 points)

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.