Godot Version
4.4.1.stable
Question
Hi! I’m just getting started with Godot and following the official documentation tutorial.
After implementing the spawn logic and modifying mob.linear_velocity and mob.scale, I decided to try changing the scale of each mob to a random value within a specified range. I used print(mob.scale) to confirm the scale is being set correctly in code, and it shows different values as expected.
However, when I run the scene, the mobs still appear at their original size — the scale change doesn’t seem to have any visual effect.
Am I missing something? Why isn’t the visual size of the mobs changing, even though mob.scale is being set?
Thanks in advance!
func _on_mob_timer_timeout():
# Create a new instance of the Mob scene.
var mob = mob_scene.instantiate()
# Choose a random location on Path2D.
var mob_spawn_location = $MobPath/MobSpawnLocation
mob_spawn_location.progress_ratio = randf()
# Set the mob's position to the random location.
mob.position = mob_spawn_location.position
# Set the mob's direction perpendicular to the path direction.
var direction = mob_spawn_location.rotation + PI / 2
# Add some randomness to the direction.
direction += randf_range(-PI / 4, PI / 4)
mob.rotation = direction
# Choose the velocity for the mob.
var velocity = Vector2(randf_range(150.0, 250.0), 0.0)
mob.linear_velocity = velocity.rotated(direction)
var rand_scale_factor := randf_range(0.3, 1)
mob.scale = Vector2(rand_scale_factor,rand_scale_factor)
# Spawn the mob by adding it to the Main scene.
add_child(mob)