Merge pull request #41 from tokc/refactor-spawn-point

Select a randomised spawn point every time the player spawns.
pull/42/head
unfa 2021-03-30 20:08:05 +02:00 committed by GitHub
commit fb7ae50b44
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 34 additions and 9 deletions

View File

@ -12,6 +12,7 @@
[ext_resource path="res://Assets/Maps/DM1/OmniFlicker.gd" type="Script" id=10]
[ext_resource path="res://Assets/Maps/DM1/SpotFlicker.gd" type="Script" id=11]
[ext_resource path="res://Assets/SFX/Ambient_Pipes.wav" type="AudioStream" id=12]
[ext_resource path="res://LevelComponents/SpawnPointsManager.gd" type="Script" id=13]
[sub_resource type="ProceduralSky" id=1]
@ -1490,9 +1491,6 @@ height = 84.58
[node name="Level" type="Spatial"]
[node name="SpawnPoint" parent="." instance=ExtResource( 9 )]
transform = Transform( 0.258819, 0, 0.965926, 0, 1, 0, -0.965926, 0, 0.258819, 2, 10, 18 )
[node name="WorldEnvironment" type="WorldEnvironment" parent="."]
environment = SubResource( 2 )
@ -1501,10 +1499,14 @@ transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 8, 13, 0 )
light_data = SubResource( 3 )
[node name="SpawnPoints" type="Spatial" parent="."]
script = ExtResource( 13 )
__meta__ = {
"_edit_lock_": true
}
[node name="SpawnPoint" parent="SpawnPoints" instance=ExtResource( 9 )]
transform = Transform( 0.258819, 0, 0.965926, 0, 1, 0, -0.965926, 0, 0.258819, 2, 10, 18 )
[node name="SpawnPoint2" parent="SpawnPoints" instance=ExtResource( 9 )]
transform = Transform( 0.258819, 0, 0.965926, 0, 1, 0, -0.965926, 0, 0.258819, 3, 10, -18 )

View File

@ -318,7 +318,7 @@ sync func remove_player(id):
player.queue_free()
func get_spawn_point():
return $Level/SpawnPoint
return $Level/SpawnPoints.get_spawn_point()
func on_peer_connected(id):
print("Peer connected with id ", id)

View File

@ -1,5 +1,6 @@
extends Spatial
func spawn(player):
player.translation = player.get_parent().to_local(global_transform.origin)
player.velocity = Vector3()
# Move the player to the starting location.
func spawn(player: Player):
# Set the player's position and rotation to our position and rotation.
player.global_transform = global_transform

View File

@ -0,0 +1,16 @@
extends Spatial
onready var spawn_points = get_children()
# Return an available spawn point.
func get_spawn_point(index: int = -1):
# If index is negative, return a randomly chosen spawn point.
if index < 0:
return spawn_points[randi() % spawn_points.size()]
# If index is positive, return a specific spawn point.
# This is mostly for debugging.
else:
# Take the modulo of the index argument, in case the number is too high.
return spawn_points[index % spawn_points.size()]

View File

@ -1,3 +1,4 @@
class_name Player
extends KinematicBody
const GRAVITY = Vector3.DOWN * 9.8 * 1.5

View File

@ -8,9 +8,14 @@
config_version=4
_global_script_classes=[ ]
_global_script_classes=[ {
"base": "KinematicBody",
"class": "Player",
"language": "GDScript",
"path": "res://Player.gd"
} ]
_global_script_class_icons={
"Player": ""
}
[application]