Game Development Diary #4 : First Course Complete
Tags: godot, godotengine, gamedev, newbie
Published: 2024-05-24 14:05:18

24/05/2024 - Friday

#Today Progress :

###-Continue Collision Detection

Detect RigidBody collisions with signals and identify bodies with Groups

first connect signal to method by clicking this menu


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/nt2foy72hyq5imzgxyxk.png)


```
func _on_body_entered(body: Node) -> void:
	if body.name == "LandingPad":
		print('you touch landingpad!')

```
use this code to detect if the character touch the destination or not

and add detection if user touch the floor then the user lose using the code below

```
func _on_body_entered(body: Node) -> void:
	if "Goal" in body.get_groups():
		print('you touch landingpad!')
	if "LoseCondition" in body.get_groups():
		print('You Lose!')

```

###-The Export Annotation
Replace ‘magic numbers’ with variables and control them from the inspector.

export a variable so it can be used in the inspector pane

```
## How much vertical force to when user move the character
@export_range(750.0,3000.0 ) var thrust: float = 1000.0
## How much force to when user move the character
@export_range(50.0,250.0 ) var torque: float = 100.0
```

and it will show in the inspector toolbar

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/73ar2foo0z38tklf0n37.png)


###-Crashing and Respawning
Use functions and get_tree() to respawn when crashing.

```
func _on_body_entered(body: Node) -> void:
	if "Goal" in body.get_groups():
		complete_level()
	if "LoseCondition" in body.get_groups():
		crash()

func complete_level():
	print('you touch landingpad!')
	get_tree().quit()

func crash():
	print('JEDER BOOM DUAR!!')
	get_tree().reload_current_scene()
```

i create two function that called when user touch floor or landing page. and i called get_tree function to reload the current scene or quit the game.

###-Loading the Next Level
Making two new levels and using the landing pads to load them.

1. First i create the other level scene
2. On the previous level landing page, create script to select thescene destination

```
extends CSGBox3D

@export_file("*.tscn") var file_path

```

on the toolbar, select the next level file path


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/wrp2chusollk8jlw10kb.png)


and we can continue to next level if we landed in the launching pad.

###-Learning Tweens
Use tweens to sequence and delay function calls.

```

func complete_level(next_level: String) -> void:
	print('you touch landingpad!')
	set_process(false)
	is_transitioning = true
	var tween = create_tween()
	tween.tween_interval(1.0)
	tween.tween_callback(
		get_tree().change_scene_to_file.bind(next_level)
		)
	

func crash():
	print('JEDER BOOM DUAR!!')
	set_process(false)
	is_transitioning = true
	var tween = create_tween()
	tween.tween_interval(1.0)
	tween.tween_callback(get_tree().reload_current_scene)

```

add tween to delay the function. so it give 1 second delay after the character touch the landing page or crash.

###-Tweening Hazards
Use the AnimatableBody3D node and Tweens to create moving obstacles for the player to dodge.

so the code will lookike this :
```
@export var destination:Vector3
@export var duration: float = 1.0

# Called when the node enters the scene tree for the first time.
func _ready() -> void:
	var tween = create_tween()
	tween.tween_property(self, "global_position", global_position+destination, duration)

```

###-Learning Audio
Use the AudioStreamPlayer node to play one off sound effects when the player crashes and completes levels.

###-Controlling Audio With Scripts
Use the AudioStreamPlayer 3D and else statements to play sounds when the player is boosting.

###-Learning Particles
Learning how to use the GPUParticles3D node and control its emitting property for the character boosters.

###-One Shot Particles
Learn how to use one shot particles for an explosion and to show the player has reached the goal.

###-change the character with complex shape / model 
Use the MeshInstance3D node and a variety of shapes to customize your player rocket

###-Coloring the character
Saving and reusing the StandardMaterial3D node to color in the player ship.

###-Building Backgrounds
Learning to use Constructive Solid Geometry to build walls and background objects for our levels.

###-Lighting the Scene
Improving the WorldEnvironment DirectionalLight3D and adding Omnilights to improve the levels appearance.

###-Exporting Game
Learn how to create files players can run by downloading templates and exporting the project.




#Resources : 
Complete Godot 3D: Code Your Own 3D Games In Godot 4! - GameDevTv Courses

#Next Step :
I will implement all knowledge I gain from this course to start developing my game!!

To Do List :

*Create a level, just simple plane with some obstacles(just basic shapes).
*Implement collision detection to the level.
*Create 3 Main Character according to the novel(Just use capsule first until I get the 3d model that suitable for the game - because I am not good at art, but I will try to create by myself first.)
*Use Input Mapper to create a button that can switch the playable character.

*After I complete all item in the To Do List, I will continue the courses.