Browse Source

Updated FPS tutorial to 3.0 (#1202)

* Updated script to 3.0 version

Use '$' instead of 'get_node'.
Functions '_process', _physics_process', '_input' and other similar functions will be detected automatically since 3.0.
LAT_Rio 7 years ago
parent
commit
9d6b4e1091
2 changed files with 14 additions and 17 deletions
  1. 7 10
      tutorials/3d/fps_tutorial/part_one.rst
  2. 7 7
      tutorials/3d/fps_tutorial/part_three.rst

+ 7 - 10
tutorials/3d/fps_tutorial/part_one.rst

@@ -149,15 +149,12 @@ Add the following code to ``Player.gd``:
     var flashlight
     var flashlight
 
 
     func _ready():
     func _ready():
-        camera = get_node("Rotation_helper/Camera")
-        camera_holder = get_node("Rotation_helper")
-
-        set_physics_process(true)
-
+        camera = $Rotation_helper/Camera
+        camera_holder = $Rotation_helper
+        
         Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED)
         Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED)
-        set_process_input(true)
-
-        flashlight = get_node("Rotation_helper/Flashlight")
+        
+        flashlight = $Rotation_helper/Flashlight
 
 
     func _physics_process(delta):
     func _physics_process(delta):
         var dir = Vector3()
         var dir = Vector3()
@@ -255,7 +252,7 @@ _________
 Now lets look at the ``_ready`` function:
 Now lets look at the ``_ready`` function:
 
 
 First we get the ``camera`` and ``rotation_helper`` nodes and store them into their variables.
 First we get the ``camera`` and ``rotation_helper`` nodes and store them into their variables.
-After that we set ``_physics_process`` to ``true``. Then we need to set the mouse mode to captured.
+Then we need to set the mouse mode to captured.
 
 
 This will hide the mouse and keep it at the center of the screen. We do this for two reasons:
 This will hide the mouse and keep it at the center of the screen. We do this for two reasons:
 The first reason being we do not want to the player to see their mouse cursor as they play.
 The first reason being we do not want to the player to see their mouse cursor as they play.
@@ -266,7 +263,7 @@ would lose focus. To assure neither of these issues happen, we capture the mouse
 .. note:: see :ref:`Input documentation <class_Input>` for the various mouse modes. We will only be using
 .. note:: see :ref:`Input documentation <class_Input>` for the various mouse modes. We will only be using
           ``MOUSE_MODE_CAPTURED`` and ``MOUSE_MODE_VISIBLE`` in this tutorial series.
           ``MOUSE_MODE_CAPTURED`` and ``MOUSE_MODE_VISIBLE`` in this tutorial series.
 
 
-Finally, we call ``set_process_input(true)``. We need to use ``_input`` so we can rotate the player and
+We need to use ``_input`` so we can rotate the player and
 camera when there is mouse motion.
 camera when there is mouse motion.
 
 
 _________
 _________

+ 7 - 7
tutorials/3d/fps_tutorial/part_three.rst

@@ -160,7 +160,7 @@ Now we need to remove a bullet from the gun when we fire. To do that, we just ne
             var scene_root = get_tree().root.get_children()[0]
             var scene_root = get_tree().root.get_children()[0]
             scene_root.add_child(clone)
             scene_root.add_child(clone)
 
 
-            clone.global_transform = get_node("Rotation_helper/Gun_fire_points/Pistol_point").global_transform
+            clone.global_transform = $Rotation_helper/Gun_fire_points/Pistol_point.global_transform
             # The bullet is a little too small (by default), so let's make it bigger!
             # The bullet is a little too small (by default), so let's make it bigger!
             clone.scale = Vector3(4, 4, 4)
             clone.scale = Vector3(4, 4, 4)
 
 
@@ -168,7 +168,7 @@ Now we need to remove a bullet from the gun when we fire. To do that, we just ne
 
 
         # Rifle bullet handeling: Send a raycast!
         # Rifle bullet handeling: Send a raycast!
         elif current_gun == "RIFLE":
         elif current_gun == "RIFLE":
-                var ray = get_node("Rotation_helper/Gun_fire_points/Rifle_point/RayCast")
+                var ray = $Rotation_helper/Gun_fire_points/Rifle_point/RayCast
                 ray.force_raycast_update()
                 ray.force_raycast_update()
 
 
                 if ray.is_colliding():
                 if ray.is_colliding():
@@ -180,7 +180,7 @@ Now we need to remove a bullet from the gun when we fire. To do that, we just ne
 
 
         # Knife bullet(?) handeling: Use an area!
         # Knife bullet(?) handeling: Use an area!
         elif current_gun == "KNIFE":
         elif current_gun == "KNIFE":
-            var area = get_node("Rotation_helper/Gun_fire_points/Knife_point/Area")
+            var area = $Rotation_helper/Gun_fire_points/Knife_point/Area
             var bodies = area.get_overlapping_bodies()
             var bodies = area.get_overlapping_bodies()
 
 
             for body in bodies:
             for body in bodies:
@@ -411,7 +411,7 @@ and insert the following code:
     var audio_node = null
     var audio_node = null
 
 
     func _ready():
     func _ready():
-        audio_node = get_node("AudioStreamPlayer")
+        audio_node = $AudioStreamPlayer
         audio_node.connect("finished", self, "destroy_self")
         audio_node.connect("finished", self, "destroy_self")
         audio_node.stop()
         audio_node.stop()
 
 
@@ -541,7 +541,7 @@ when a bullet is fired. Go to ``fire_bullet`` and add the following:
             var scene_root = get_tree().root.get_children()[0]
             var scene_root = get_tree().root.get_children()[0]
             scene_root.add_child(clone)
             scene_root.add_child(clone)
 
 
-            clone.global_transform = get_node("Rotation_helper/Gun_fire_points/Pistol_point").global_transform
+            clone.global_transform = $Rotation_helper/Gun_fire_points/Pistol_point.global_transform
             # The bullet is a little too small (by default), so let's make it bigger!
             # The bullet is a little too small (by default), so let's make it bigger!
             clone.scale = Vector3(4, 4, 4)
             clone.scale = Vector3(4, 4, 4)
 
 
@@ -550,7 +550,7 @@ when a bullet is fired. Go to ``fire_bullet`` and add the following:
 
 
         # Rifle bullet handeling: Send a raycast!
         # Rifle bullet handeling: Send a raycast!
         elif current_gun == "RIFLE":
         elif current_gun == "RIFLE":
-            var ray = get_node("Rotation_helper/Gun_fire_points/Rifle_point/RayCast")
+            var ray = Rotation_helper/Gun_fire_points/Rifle_point/RayCast
             ray.force_raycast_update()
             ray.force_raycast_update()
 
 
             if ray.is_colliding():
             if ray.is_colliding():
@@ -563,7 +563,7 @@ when a bullet is fired. Go to ``fire_bullet`` and add the following:
 
 
         # Knife bullet(?) handeling: Use an area!
         # Knife bullet(?) handeling: Use an area!
         elif current_gun == "KNIFE":
         elif current_gun == "KNIFE":
-            var area = get_node("Rotation_helper/Gun_fire_points/Knife_point/Area")
+            var area = $Rotation_helper/Gun_fire_points/Knife_point/Area
             var bodies = area.get_overlapping_bodies()
             var bodies = area.get_overlapping_bodies()
 
 
             for body in bodies:
             for body in bodies: