Skip to content

Commit

Permalink
Merge pull request #687 from rburing/set_physics_params_before_spawn
Browse files Browse the repository at this point in the history
Dodge the Creeps: Set the physics parameters of the mob before adding it to the scene tree
  • Loading branch information
aaronfranke authored Mar 13, 2022
2 parents 14580c5 + 9e096b1 commit 2190128
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions 2d/dodge_the_creeps/Main.gd
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,13 @@ func new_game():


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

# Choose a random location on Path2D.
var mob_spawn_location = get_node("MobPath/MobSpawnLocation")
mob_spawn_location.offset = randi()

# Create a Mob instance and add it to the scene.
var mob = mob_scene.instance()
add_child(mob)

# Set the mob's direction perpendicular to the path direction.
var direction = mob_spawn_location.rotation + PI / 2

Expand All @@ -48,6 +47,8 @@ func _on_MobTimer_timeout():
var velocity = Vector2(rand_range(150.0, 250.0), 0.0)
mob.linear_velocity = velocity.rotated(direction)

# Spawn the mob by adding it to the Main scene.
add_child(mob)

func _on_ScoreTimer_timeout():
score += 1
Expand Down

0 comments on commit 2190128

Please sign in to comment.