From 5f4f7e196bc2321db26d1eda54966e163fa86437 Mon Sep 17 00:00:00 2001 From: Hugo Locurcio Date: Thu, 10 Apr 2025 17:13:13 +0200 Subject: [PATCH] Add C# integer casts where needed in Your first 2D game --- getting_started/first_3d_game/04.mob_scene.rst | 4 ++-- getting_started/first_3d_game/07.killing_player.rst | 2 +- getting_started/first_3d_game/09.adding_animations.rst | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/getting_started/first_3d_game/04.mob_scene.rst b/getting_started/first_3d_game/04.mob_scene.rst index 5c63fd6db46..02f81c949a6 100644 --- a/getting_started/first_3d_game/04.mob_scene.rst +++ b/getting_started/first_3d_game/04.mob_scene.rst @@ -202,7 +202,7 @@ We got a random position, now we need a ``random_speed``. ``randi_range()`` will // ... // We calculate a random speed (integer). - int randomSpeed = GD.RandRange(MinSpeed, MaxSpeed); + int randomSpeed = (int)GD.RandRange(MinSpeed, MaxSpeed); // We calculate a forward velocity that represents the speed. Velocity = Vector3.Forward * randomSpeed; // We then rotate the velocity vector based on the mob's Y rotation @@ -316,7 +316,7 @@ Here is the complete ``mob.gd`` script for reference. RotateY((float)GD.RandRange(-Mathf.Pi / 4.0, Mathf.Pi / 4.0)); // We calculate a random speed (integer). - int randomSpeed = GD.RandRange(MinSpeed, MaxSpeed); + int randomSpeed = (int)GD.RandRange(MinSpeed, MaxSpeed); // We calculate a forward velocity that represents the speed. Velocity = Vector3.Forward * randomSpeed; // We then rotate the velocity vector based on the mob's Y rotation diff --git a/getting_started/first_3d_game/07.killing_player.rst b/getting_started/first_3d_game/07.killing_player.rst index f29363f6f94..941ccb0b133 100644 --- a/getting_started/first_3d_game/07.killing_player.rst +++ b/getting_started/first_3d_game/07.killing_player.rst @@ -288,7 +288,7 @@ Next is ``mob.gd``. RotateY((float)GD.RandRange(-Mathf.Pi / 4.0, Mathf.Pi / 4.0)); // We calculate a random speed (integer) - int randomSpeed = GD.RandRange(MinSpeed, MaxSpeed); + int randomSpeed = (int)GD.RandRange(MinSpeed, MaxSpeed); // We calculate a forward velocity that represents the speed. Velocity = Vector3.Forward * randomSpeed; // We then rotate the velocity vector based on the mob's Y rotation diff --git a/getting_started/first_3d_game/09.adding_animations.rst b/getting_started/first_3d_game/09.adding_animations.rst index 01c809d930e..eab65eb4973 100644 --- a/getting_started/first_3d_game/09.adding_animations.rst +++ b/getting_started/first_3d_game/09.adding_animations.rst @@ -593,7 +593,7 @@ And the *Mob*'s script. RotateY((float)GD.RandRange(-Mathf.Pi / 4.0, Mathf.Pi / 4.0)); // We calculate a random speed (integer). - int randomSpeed = GD.RandRange(MinSpeed, MaxSpeed); + int randomSpeed = (int)GD.RandRange(MinSpeed, MaxSpeed); // We calculate a forward velocity that represents the speed. Velocity = Vector3.Forward * randomSpeed; // We then rotate the velocity vector based on the mob's Y rotation