From e08870b788daf6d206f291b12af9448e891d6946 Mon Sep 17 00:00:00 2001 From: Stefano Pigozzi Date: Sun, 3 Apr 2022 17:48:53 +0200 Subject: [PATCH] :wrench: Fix RNGs --- src/entities/behaviours/ErraticMovement.gd | 7 ++++++- src/entities/behaviours/SpriteRandomRotation.gd | 9 +++------ 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/src/entities/behaviours/ErraticMovement.gd b/src/entities/behaviours/ErraticMovement.gd index bfaa218..653fa5c 100644 --- a/src/entities/behaviours/ErraticMovement.gd +++ b/src/entities/behaviours/ErraticMovement.gd @@ -5,7 +5,12 @@ export var movement_per_second: float = 16.0 onready var target: KinematicBody2D = get_parent() -onready var rng = RandomNumberGenerator.new() +var rng: RandomNumberGenerator + + +func _ready(): + rng = RandomNumberGenerator.new() + rng.randomize() func _physics_process(_delta): diff --git a/src/entities/behaviours/SpriteRandomRotation.gd b/src/entities/behaviours/SpriteRandomRotation.gd index af570cf..5a94ccb 100644 --- a/src/entities/behaviours/SpriteRandomRotation.gd +++ b/src/entities/behaviours/SpriteRandomRotation.gd @@ -1,11 +1,8 @@ extends Sprite -var rng : RandomNumberGenerator = RandomNumberGenerator.new() +var rng: RandomNumberGenerator func _ready(): + rng = RandomNumberGenerator.new() rng.randomize() - self.rotate(rng.randf_range(0,360)) - -# Called every frame. 'delta' is the elapsed time since the previous frame. -#func _process(delta): -# pass + self.rotate(rng.randf() * 2 * PI)