You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The docs used randi_range instead of randf_range for the mob's
random_speed which did not match the source and would cause a bug with
integer division when using it to scale the animation speed.
We got a random position, now we need a ``random_speed``. ``randi_range()`` will be useful as it gives random int values, and we will use ``min_speed`` and ``max_speed``.
182
-
``random_speed`` is just an integer, and we just use it to multiply our ``CharacterBody3D.velocity``. After ``random_speed`` is applied, we rotate ``CharacterBody3D.velocity`` Vector3 towards the player.
181
+
We got a random position, now we need a ``random_speed``. ``randf_range()`` will be useful as it gives random float values, and we will use ``min_speed`` and ``max_speed``.
182
+
``random_speed`` is just an float, and we just use it to multiply our ``CharacterBody3D.velocity``. After ``random_speed`` is applied, we rotate ``CharacterBody3D.velocity`` Vector3 towards the player.
183
183
184
184
.. tabs::
185
185
.. code-tab:: gdscript GDScript
186
186
187
187
func initialize(start_position, player_position):
188
188
# ...
189
189
190
-
# We calculate a random speed (integer)
191
-
var random_speed = randi_range(min_speed, max_speed)
190
+
# We calculate a random speed (float)
191
+
var random_speed = randf_range(min_speed, max_speed)
192
192
# We calculate a forward velocity that represents the speed.
193
193
velocity = Vector3.FORWARD * random_speed
194
194
# We then rotate the velocity vector based on the mob's Y rotation
@@ -201,8 +201,8 @@ We got a random position, now we need a ``random_speed``. ``randi_range()`` will
201
201
{
202
202
// ...
203
203
204
-
// We calculate a random speed (integer).
205
-
int randomSpeed = GD.RandRange(MinSpeed, MaxSpeed);
0 commit comments