From c3f84c76811f6554ce1f63839b4dab48d0bd791c Mon Sep 17 00:00:00 2001 From: denizk0461 Date: Tue, 23 Jul 2024 21:22:05 +0200 Subject: [PATCH] added a safeguard so that balls can't fly straight horizontally or vertically --- balls/ball.gd | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/balls/ball.gd b/balls/ball.gd index 5cfc5bf..42495cd 100644 --- a/balls/ball.gd +++ b/balls/ball.gd @@ -10,7 +10,18 @@ var _velocity: Vector2 var deg: float 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): _velocity.x = speed * _speed_mult * _direction.x * delta