Fixed team interactions
This commit is contained in:
parent
2bfbfa5089
commit
917d52680c
5 changed files with 45 additions and 21 deletions
|
|
@ -36,6 +36,9 @@ properties/2/replication_mode = 1
|
|||
properties/3/path = NodePath(".:hp")
|
||||
properties/3/spawn = true
|
||||
properties/3/replication_mode = 1
|
||||
properties/4/path = NodePath(".:team")
|
||||
properties/4/spawn = true
|
||||
properties/4/replication_mode = 2
|
||||
|
||||
[sub_resource type="Animation" id="Animation_a8ls1"]
|
||||
length = 0.001
|
||||
|
|
@ -317,5 +320,14 @@ libraries = {
|
|||
&"": SubResource("AnimationLibrary_a8ls1")
|
||||
}
|
||||
|
||||
[node name="TeamUpdater" type="Node" parent="." node_paths=PackedStringArray("player")]
|
||||
script = ExtResource("7_a8ls1")
|
||||
player = NodePath("..")
|
||||
layer = true
|
||||
inverse = true
|
||||
|
||||
[connection signal="spawned" from="." to="Camera3D/RayCast3D/TeamUpdater" method="on_spawned"]
|
||||
[connection signal="spawned" from="." to="TeamUpdater" method="on_spawned"]
|
||||
|
||||
[editable path="Camera3D/molikman_hands"]
|
||||
[editable path="WeaponSystem/StartingPistol"]
|
||||
|
|
|
|||
|
|
@ -9,38 +9,30 @@ func _ready() -> void:
|
|||
match team:
|
||||
Session.TEAMS.ATTACK:
|
||||
for attacker in Lobby.attack_team:
|
||||
spawn_attacker(attacker)
|
||||
spawn_player(attacker)
|
||||
Session.TEAMS.DEFENCE:
|
||||
for defender in Lobby.defence_team:
|
||||
spawn_defender(defender)
|
||||
spawn_player(defender)
|
||||
Session.TEAMS.SPECTATE:
|
||||
for specator in Lobby.specators_team:
|
||||
spawn_spectator(specator)
|
||||
|
||||
func spawn_defender(id: int) -> void:
|
||||
func spawn_player(id: int) -> void:
|
||||
var player: PackedScene = load("res://scenes/molikman.tscn")
|
||||
var inst: Player = player.instantiate()
|
||||
inst.name = str(id)
|
||||
inst.team = Session.TEAMS.DEFENCE
|
||||
|
||||
deferred_setup.bind(inst).call_deferred()
|
||||
|
||||
func spawn_attacker(id: int) -> void:
|
||||
var player: PackedScene = load("res://scenes/molikman.tscn")
|
||||
var inst: Player = player.instantiate()
|
||||
inst.name = str(id)
|
||||
inst.team = Session.TEAMS.ATTACK
|
||||
|
||||
deferred_setup.bind(inst).call_deferred()
|
||||
deferred_setup.bind(inst,team).call_deferred()
|
||||
|
||||
func spawn_spectator(id: int) -> void:
|
||||
var spectator: PackedScene = load("res://scenes/spectator.tscn")
|
||||
var inst = spectator.instantiate()
|
||||
inst.name = str(id)
|
||||
deferred_setup.bind(inst).call_deferred()
|
||||
deferred_setup.bind(inst,Session.TEAMS.SPECTATE).call_deferred()
|
||||
|
||||
func deferred_setup(what: Node3D):
|
||||
func deferred_setup(what: Node3D, new_team: Session.TEAMS):
|
||||
get_tree().current_scene.add_child(what)
|
||||
var distance = randf_range(0,spawn_radius)
|
||||
var angle = randf_range(0,TAU)
|
||||
what.set_start_position.rpc_id(int(what.name),global_position + Vector3.RIGHT.rotated(Vector3.UP,angle) * distance)
|
||||
var new_position = global_position + Vector3.RIGHT.rotated(Vector3.UP,angle) * distance
|
||||
what.set_after_spawn.rpc_id(int(what.name),new_position,new_team)
|
||||
|
|
|
|||
|
|
@ -1,10 +1,23 @@
|
|||
extends Node
|
||||
|
||||
@export var player: Player
|
||||
@export var layer: bool
|
||||
@export var inverse: bool
|
||||
|
||||
const ATTACK_LAYER: int = 0b10000
|
||||
const DEFENCE_LAYER: int = 0b100000
|
||||
|
||||
func _ready() -> void:
|
||||
func on_spawned() -> void:
|
||||
var mask = (ATTACK_LAYER if (player.team == Session.TEAMS.DEFENCE != inverse) else DEFENCE_LAYER)
|
||||
if layer:
|
||||
get_parent().collision_layer |= mask
|
||||
else:
|
||||
get_parent().collision_mask |= mask
|
||||
global_update.rpc(layer,mask)
|
||||
|
||||
get_parent().collision_mask |= (ATTACK_LAYER if player.team == Session.TEAMS.DEFENCE else DEFENCE_LAYER)
|
||||
@rpc
|
||||
func global_update(new_layer,mask) -> void:
|
||||
if new_layer:
|
||||
get_parent().collision_layer |= mask
|
||||
else:
|
||||
get_parent().collision_mask |= mask
|
||||
|
|
|
|||
|
|
@ -4,6 +4,8 @@ class_name Player
|
|||
|
||||
@export var team: Session.TEAMS
|
||||
|
||||
signal spawned
|
||||
|
||||
const MAX_HP = 100
|
||||
|
||||
@export var hp: int = 100:
|
||||
|
|
@ -30,10 +32,15 @@ func _physics_process(_delta: float) -> void:
|
|||
move_and_slide()
|
||||
|
||||
func die() -> void:
|
||||
if not is_multiplayer_authority():
|
||||
return
|
||||
|
||||
global_position = TEMP_start_pos
|
||||
hp = MAX_HP
|
||||
|
||||
@rpc("any_peer","call_local","reliable")
|
||||
func set_start_position(start_position: Vector3):
|
||||
func set_after_spawn(start_position: Vector3,new_team: int):
|
||||
global_position = start_position
|
||||
TEMP_start_pos = global_position
|
||||
team = new_team as Session.TEAMS
|
||||
spawned.emit()
|
||||
|
|
|
|||
|
|
@ -30,5 +30,5 @@ func _input(event: InputEvent) -> void:
|
|||
rotate_camera(-event.relative.x * SENSITIVITY,-event.relative.y * SENSITIVITY)
|
||||
|
||||
@rpc("any_peer","call_local","reliable")
|
||||
func set_start_position(start_position: Vector3):
|
||||
func set_after_spawn(start_position: Vector3, _team: int):
|
||||
global_position = start_position
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue