added a safeguard so that balls can't fly straight horizontally or vertically

This commit is contained in:
2024-07-23 21:22:05 +02:00
parent 65accbc2c2
commit c3f84c7681
+12 -1
View File
@@ -10,7 +10,18 @@ var _velocity: Vector2
var deg: float var deg: float
func _ready(): func _ready():
_direction = Vector2.UP.rotated(deg_to_rad(randf_range(0.0, 360.0))) var randvalue = _get_rand_direction()
_direction = Vector2.UP.rotated(deg_to_rad(randvalue))
func _get_rand_direction() -> float:
var value = randf_range(0.0, 360.0)
if value < 10 \
or (value >= 80 and value < 100) \
or (value >= 170 and value < 190) \
or (value >= 260 and value < 280) \
or value >= 350:
return _get_rand_direction()
return value
func _physics_process(delta): func _physics_process(delta):
_velocity.x = speed * _speed_mult * _direction.x * delta _velocity.x = speed * _speed_mult * _direction.x * delta