Godot Version
4.3
Question
Hello, I am very new to Godot, I tried to do a “simple” scene where bubbles (sprites) appear at the bottom of the screen, they have randomized size (scale) and spawn point, and then they rise up.
I managed to do it, but there is one peculiar thing - the SPEED of each bubble is different based on their size (scale). I can clearly see the bubbles overtake each other, it’s not just an illusion, they are DEFINITELY moving at different speeds.
Is that normal behaviour or a bug? Because funnily enough, with this bug/feature the scene looks much nicer, big bubbles move faster, smaller slower so it gives it a bit of a 3D effect, but I just want to know WHY that is happening. I think I clearly defined what the speed of the sprite moving up should be.
Anyway, here is my full script:
FIRST FILE:
extends Node2D
@export var max_number_of_bubbles : int = 150
var time_between_spawns : float = 0.2
var current_number_of_bubbles : int = 0
var time_accumulator : float = 0.0
var bubble_scene = preload(“res://Scenes/bubble.tscn”)
func _bubble_spawn():
var bubble = bubble_scene.instantiate()
add_child(bubble)
var bubble_size = randf_range(0.3, 1.3)
bubble.scale = Vector2.ONE * bubble_size
current_number_of_bubbles += 1
bubble.position.x = randi_range(-1050, 1050)
bubble.position.y = randi_range(450, 560)
func _process(delta: float) → void:
if current_number_of_bubbles > max_number_of_bubbles:
return
time_accumulator += delta
if time_accumulator >= time_between_spawns:
time_accumulator = 0
_bubble_spawn()
SECOND FILE:
extends Sprite2D
var moving_speed : int = 50
func _process(delta: float) → void:
position.y -= moving_speed * delta
I think the last line CLEARLY says that the speed should be moving speed * delta, so the same for every sprite. Yet it’s different.
Any help is appreciated!