PacktPublishing / Game-Development-with-Blender-and-Godot

Game Development with Blender and Godot, published by Packt
MIT License
64 stars 17 forks source link

Chapter 12 for Godot 4.2 #6

Open dragonforge-dev opened 1 month ago

dragonforge-dev commented 1 month ago

Page 235:

  1. For the following Step numbers:
  2. Just click Toggle preview sunlight and Toggle preview environment in the toolbar to the left of Transform and View.
  3. Add a StaticBody3D node.
  4. Add a CollisionShape3D node.
  5. It's the Size section, and to encapsulate it you need 0.25, 0.275, 0.13
  6. It's the Position section, and set the z to 0.045

Page 237:

  1. Step 1: Exporting nodes is much simpler in Godot 4, just use: @export var note_trigger: Node3D
  2. Step 3: Instantiate the UI scene as a child of the root node, then follow the Step 3 directions.
  3. Step 4: The code is:
    
    extends CanvasLayer

@export var note_trigger: Node3D

func _ready(): note_trigger.connect("show_note", on_show_note)

func on_show_note(): $Panel.visible = true


**Page 240:** The first three steps need modifications.
1. The **Navigation** node has been renamed `NavigationRegion3D`. The **NavigationMesh** is now a property instead of a node. Click on the empty **NavigationMesh** property and select **New NavigationMesh**.
2. Drop all of these things under the `NavigationRegion3D` node instead.
3. Skip this step, we did it in **Step 1**.

**Page 243:**
1. In **Step 2** Instead of **KinematicBody** we are going to use a `CharacterBody3D` node. Likewise, we are going to use `CollisionShape3D` and `MeshInstance3D` nodes.
2. Skip **Step II** under **Steps 3 & 4**.
3. In **Step 5** the `0.9` goes in the `y` **Position** field under **Transform**.

**Page 244:**
1. **Step 1:** **StaticBody3D** and **CollisionShape3D**.
2. **Step 3:** It's the **Size** settings, not **Extent**.

**Page 245:** In Step 2 create your own Player.gd script and paste this in:

extends CharacterBody3D

@onready var camera:Camera3D = get_viewport().get_camera_3d() @onready var space_state = get_world_3d().direct_space_state @onready var default_3d_map_rid: RID = get_world_3d().get_navigation_map() const DISTANCE_THRESHOLD:= 1 const SPEED:= 3

var path:= [] var path_index:=0

func _unhandled_input(event): if event is InputEventMouseButton and event.button_index == 1: find_path(event)

func _physics_process(_delta): move_along()

func find_path(event): var from = camera.project_ray_origin(event.position) var to = from + camera.project_ray_normal(event.position) * 100 var query = PhysicsRayQueryParameters3D.create(from, to) var result = space_state.intersect_ray(query)

if result and result.collider:
    path = NavigationServer3D.map_get_path(default_3d_map_rid, global_transform.origin, result.position, true)
    path_index = 0

func move_along(): if !path or path_index == path.size(): return

var distance_to_next_step = global_transform.origin.distance_to(path[path_index])
velocity = path[path_index] - global_transform.origin

if distance_to_next_step < DISTANCE_THRESHOLD:
    path_index += 1
else:
    move_and_slide()


**Page 247:** Don't do steps 1 & 2 at the bottom of the page. The connection to the **NavigationRegion3D** node is not necessary, that code has been removed. Just **Press** `F5`.
dragonforge-dev commented 1 month ago

@mrunion Chapter 12 almost done. I got distracted by the first half of the book. Thankfully, Blender hasn't changed all that much. I need to finish the importing Clara bit, and then do Chapter 13. I'll tag you when I'm done. Enjoy all the other chapters. :)