added a safeguard so that balls can't fly straight horizontally or vertically
This commit is contained in:
+12
-1
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user