Godot Version
4.2.2.
Question
Why does “mob_spawn_location.progress = randf()” set the mob_spawn_location’s position to randf()? I thought position and progress of a PathFollow2D node are different things
I’ve determined this is the case with debug prints in the code
Code snippet of the function that’s problematic
func _on_mob_timer_timeout():
# Creating the mob
var mob = mob_scene.instantiate()
# Setting it up
var mob_spawn_location = $MobPath/MobSpawnLocation
mob_spawn_location.progress = randf()
mob.position = mob_spawn_location.position
print(mob_spawn_location.position)
print(mob.position)
print("..........")
var direction = mob_spawn_location.rotation + PI / 2
direction += randf_range(- PI / 4, PI / 4)
mob.rotation = direction
var velocity = Vector2(randf_range(150, 250), 0)
mob.linear_velocity = velocity.rotated(direction)
# Instantiating it on the scene
add_child(mob)
Entire code of main scene script
extends Node
# Fields
@export var mob_scene: PackedScene
var score = 0
# Called when the node enters the scene tree for the first time
func _ready():
new_game()
# Called every frame
func _process(delta):
pass
# Connected with the Players hit() signal
func game_over():
$ScoreTimer.stop()
$MobTimer.stop()
func new_game():
score = 0
$Player.start($StartPosition.position)
$StartTimer.start()
# ----- Timers -----
func _on_mob_timer_timeout():
# Creating the mob
var mob = mob_scene.instantiate()
# Setting it up
var mob_spawn_location = $MobPath/MobSpawnLocation
mob_spawn_location.progress = randf()
mob.position = mob_spawn_location.position
print(mob_spawn_location.position)
print(mob.position)
print("..........")
var direction = mob_spawn_location.rotation + PI / 2
direction += randf_range(- PI / 4, PI / 4)
mob.rotation = direction
var velocity = Vector2(randf_range(150, 250), 0)
mob.linear_velocity = velocity.rotated(direction)
# Instantiating it on the scene
add_child(mob)
func _on_score_timer_timeout():
score += 1
func _on_start_timer_timeout():
$MobTimer.start()
$ScoreTimer.start()