Merge pull request #687 from rburing/set_physics_params_before_spawn
Dodge the Creeps: Set the physics parameters of the mob before adding it to the scene tree
This commit is contained in:
commit
2190128fd3
|
@ -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
|
||||
|
||||
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue