From f58e0cfab3c1e76d79eecfd3a2b95fd7747abfd6 Mon Sep 17 00:00:00 2001 From: Luna Date: Mon, 22 Jan 2018 22:07:07 -0500 Subject: [PATCH] Make players spawn on side depending on team Also add variation in spawn point, so that all spawns are not on top of each other --- scenes/world.tscn | 9 +++++++++ scripts/lobby.gd | 1 + scripts/player.gd | 18 ++++++++++++++++-- 3 files changed, 26 insertions(+), 2 deletions(-) diff --git a/scenes/world.tscn b/scenes/world.tscn index bd31df6..99143b7 100644 --- a/scenes/world.tscn +++ b/scenes/world.tscn @@ -176,4 +176,13 @@ lines_skipped = 0 max_lines_visible = -1 _sections_unfolded = [ "Anchor", "Focus", "Grow Direction", "Hint", "Margin", "Material", "Mouse", "Pause", "Rect", "Size Flags", "Theme", "Visibility", "custom_colors", "custom_constants", "custom_fonts", "custom_styles" ] +[node name="LeftSpawn" type="Spatial" parent="." index="6"] + +transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 2.96426, 9.36109 ) +_sections_unfolded = [ "Transform" ] + +[node name="RightSpawn" type="Spatial" parent="." index="7"] + +transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 3.87156, 0 ) + diff --git a/scripts/lobby.gd b/scripts/lobby.gd index da38b3b..c44222f 100644 --- a/scripts/lobby.gd +++ b/scripts/lobby.gd @@ -137,6 +137,7 @@ remote func pre_configure_game(): var player = load("res://scenes/heroes/" + str(hero) + ".tscn").instance() player.set_name(str(p)) player.set_network_master(p) + player.player_info = player_info[p] get_node("/root/world/players").call_deferred("add_child", player) rpc_id(1, "done_preconfiguring", self_peer_id) diff --git a/scripts/player.gd b/scripts/player.gd index ae99045..d7fe73f 100644 --- a/scripts/player.gd +++ b/scripts/player.gd @@ -6,14 +6,13 @@ var view_sensitivity = 0.25 var yaw = 0 var pitch = 0 -var timer = 0 - # Walking speed and jumping height are defined later. var walk_speed = 2 var jump_speed = 3 const air_accel = .6 var floor_friction = 0.92 var air_friction = 0.98 +var player_info # Set by lobby var health = 100 var stamina = 10000 @@ -34,6 +33,21 @@ func _ready(): if is_network_master(): get_node("Yaw/Pitch/Camera").make_current() + spawn() + +func spawn(): + var placement = Vector3() + var x_varies = 10 + var y_varies = 20 + # No Z, because that's the left-right question + if player_info.is_right_team: + placement = get_node("/root/world/RightSpawn").get_translation() + else: + placement = get_node("/root/world/LeftSpawn").get_translation() + # So we don't all spawn on top of each other + placement.x += rand_range(0, x_varies) + placement.y += rand_range(0, y_varies) + set_translation(placement) func _input(event): if is_network_master():