Skip to content
This repository has been archived by the owner on Dec 4, 2023. It is now read-only.

Set the physics parameters of the mob before adding it to the scene tree #4

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions dodge_the_creeps_3d/Main.gd
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,21 @@ func _unhandled_input(event):


func _on_MobTimer_timeout():
# Create a Mob instance and add it to the scene.
# Create a new instance of the Mob scene.
var mob = mob_scene.instance()

# Choose a random location on Path2D.
# Choose a random location on the SpawnPath.
var mob_spawn_location = get_node("SpawnPath/SpawnLocation")
mob_spawn_location.unit_offset = randf()

# Communicate the spawn location and the player's location to the mob.
var player_position = $Player.transform.origin
mob.initialize(mob_spawn_location.translation, player_position)

# Spawn the mob by adding it to the Main scene.
add_child(mob)
# We connect the mob to the score label to update the score upon squashing a mob.
mob.connect("squashed", $UserInterface/ScoreLabel, "_on_Mob_squashed")
mob.initialize(mob_spawn_location.translation, player_position)


func _on_Player_hit():
Expand Down
3 changes: 1 addition & 2 deletions dodge_the_creeps_3d/Mob.gd
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ func _physics_process(_delta):


func initialize(start_position, player_position):
translation = start_position
look_at(player_position, Vector3.UP)
look_at_from_position(start_position, player_position, Vector3.UP)
rotate_y(rand_range(-PI / 4, PI / 4))

var random_speed = rand_range(min_speed, max_speed)
Expand Down