diff --git a/levels/prototype_scene.tscn b/levels/prototype_scene.tscn index d3f540e..f9a1596 100644 --- a/levels/prototype_scene.tscn +++ b/levels/prototype_scene.tscn @@ -1,7 +1,6 @@ -[gd_scene load_steps=24 format=3 uid="uid://cqrh2cc7m2i7f"] +[gd_scene load_steps=21 format=3 uid="uid://cqrh2cc7m2i7f"] [ext_resource type="Environment" uid="uid://d0cfgtx2yxw13" path="res://environments/prototype_environment.tres" id="1_i6jab"] -[ext_resource type="Script" uid="uid://ypgm3aplt78m" path="res://scripts/multiplayer/spawn_system/team_spawner.gd" id="4_pi0y7"] [ext_resource type="Material" uid="uid://bx3f5vx71ynh5" path="res://materials/Graymat.tres" id="4_y6i55"] [ext_resource type="Material" uid="uid://dynpcduei1wfn" path="res://materials/Bluemat.tres" id="4_yx0ab"] [ext_resource type="Material" uid="uid://mlha6r17v2en" path="res://materials/DarkBluemat.tres" id="5_bno23"] @@ -15,22 +14,9 @@ [ext_resource type="Script" uid="uid://dk1gjbuydemmb" path="res://scripts/multiplayer/plant_site/plant_site.gd" id="8_oujx2"] [ext_resource type="Script" uid="uid://b4cpux52fmx5o" path="res://scripts/multiplayer/plant_site/plant_deadzone.gd" id="9_1wlgq"] [ext_resource type="Material" uid="uid://c6xa4phihtya2" path="res://materials/Redmat.tres" id="9_ysk2e"] +[ext_resource type="Script" path="res://scripts/multiplayer/spawn_system/team_spawner.gd" id="10_02ic3"] [ext_resource type="Script" uid="uid://3i00rp8urth7" path="res://scripts/object_container.gd" id="11_02ic3"] -[sub_resource type="Animation" id="Animation_y6i55"] -length = 0.001 - -[sub_resource type="Animation" id="Animation_pi0y7"] -resource_name = "main" -length = 5.0 -loop_mode = 2 - -[sub_resource type="AnimationLibrary" id="AnimationLibrary_bno23"] -_data = { -&"RESET": SubResource("Animation_y6i55"), -&"main": SubResource("Animation_pi0y7") -} - [sub_resource type="BoxShape3D" id="BoxShape3D_ysk2e"] size = Vector3(15.324341, 0.96273804, 21.381592) @@ -233,30 +219,24 @@ operation = 2 size = Vector3(20.339264, 4.566284, 3.4625244) material = ExtResource("7_8bje3") -[node name="AnimationPlayer" type="AnimationPlayer" parent="."] -libraries = { -&"": SubResource("AnimationLibrary_bno23") -} -autoplay = "main" - [node name="PlayersContainer" type="Node3D" parent="." node_paths=PackedStringArray("exlusion_list")] script = ExtResource("11_02ic3") exlusion_list = [NodePath("DefenceSpawn"), NodePath("AttackSpawn"), NodePath("SpectatorSpawn"), NodePath("MultiplayerSpawner")] [node name="DefenceSpawn" type="Marker3D" parent="PlayersContainer"] transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 37.170197, 0.5180037, -11.271502) -script = ExtResource("4_pi0y7") +script = ExtResource("10_02ic3") spawn_radius = 10.0 [node name="AttackSpawn" type="Marker3D" parent="PlayersContainer"] transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -31.553003, 0.5180037, 20.371899) -script = ExtResource("4_pi0y7") +script = ExtResource("10_02ic3") team = 1 spawn_radius = 5.0 [node name="SpectatorSpawn" type="Marker3D" parent="PlayersContainer"] transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 4.1422176, 39.792877, -1.3889732) -script = ExtResource("4_pi0y7") +script = ExtResource("10_02ic3") team = 2 spawn_radius = 10.0 @@ -269,7 +249,7 @@ script = ExtResource("11_02ic3") exlusion_list = [NodePath("MultiplayerSpawner"), NodePath("Bomb")] [node name="MultiplayerSpawner" type="MultiplayerSpawner" parent="DynamicObjectsContainer"] -_spawnable_scenes = PackedStringArray("uid://dtbpyfdawb02b", "uid://cxdgk74ln5xpn", "uid://dgfqppi21c2u0") +_spawnable_scenes = PackedStringArray("uid://cxdgk74ln5xpn", "uid://dgfqppi21c2u0") spawn_path = NodePath("..") script = ExtResource("6_oujx2") diff --git a/project.godot b/project.godot index 1c80d74..f10df4b 100644 --- a/project.godot +++ b/project.godot @@ -166,3 +166,7 @@ menu_settings={ 3d_physics/layer_5="Players Attack Team" 3d_physics/layer_6="Players Defence Team" 3d_physics/layer_7="Interactible" + +[physics] + +3d/default_gravity=39.2 diff --git a/scenes/molikman.tscn b/scenes/molikman.tscn index fc594e7..c782b2f 100644 --- a/scenes/molikman.tscn +++ b/scenes/molikman.tscn @@ -7620,6 +7620,9 @@ height = 3.7087402 properties/0/path = NodePath("PlayerInput:direction") properties/0/spawn = true properties/0/replication_mode = 1 +properties/1/path = NodePath("PlayerInput:compressed_states") +properties/1/spawn = true +properties/1/replication_mode = 1 [node name="Player" type="CharacterBody3D" node_paths=PackedStringArray("weapon_models")] collision_layer = 2 @@ -8769,7 +8772,7 @@ script = ExtResource("8_f1ej7") current_state = NodePath("Stand") metadata/_custom_type_script = "uid://3777rkbebgjm" -[node name="Crouch" type="Node" parent="BodyStateMachine" node_paths=PackedStringArray("stand_up_area", "player", "player_movement", "animation_player", "weapon_system")] +[node name="Crouch" type="Node" parent="BodyStateMachine" node_paths=PackedStringArray("stand_up_area", "player", "player_movement", "player_input", "animation_player", "weapon_system")] script = ExtResource("9_oprun") max_speed = 3.0 acceleration = 50.0 @@ -8777,36 +8780,38 @@ deceleration = 50.0 stand_up_area = NodePath("../../StandArea") player = NodePath("../..") player_movement = NodePath("../../PlayerMovement") +player_input = NodePath("../../PlayerInput") animation_player = NodePath("../../AnimationPlayer") weapon_system = NodePath("../../WeaponSystem") -[node name="Stand" type="Node" parent="BodyStateMachine" node_paths=PackedStringArray("player", "player_movement", "weapon_system", "audio")] +[node name="Stand" type="Node" parent="BodyStateMachine" node_paths=PackedStringArray("player", "player_movement", "player_input", "weapon_system", "audio")] script = ExtResource("10_a8ls1") max_speed = 6.0 acceleration = 100.0 deceleration = 50.0 -JUMP_VELOCITY = 6.0 player = NodePath("../..") player_movement = NodePath("../../PlayerMovement") +player_input = NodePath("../../PlayerInput") weapon_system = NodePath("../../WeaponSystem") audio = NodePath("../../StepAudio") step_delay = 0.25 step_speed_curve = SubResource("Curve_fbysy") -[node name="Walk" type="Node" parent="BodyStateMachine" node_paths=PackedStringArray("player", "player_movement", "weapon_system")] +[node name="Walk" type="Node" parent="BodyStateMachine" node_paths=PackedStringArray("player", "player_movement", "player_input", "weapon_system")] script = ExtResource("11_qfm1y") max_speed = 3.0 acceleration = 50.0 deceleration = 50.0 player = NodePath("../..") player_movement = NodePath("../../PlayerMovement") +player_input = NodePath("../../PlayerInput") weapon_system = NodePath("../../WeaponSystem") [node name="Fall" type="Node" parent="BodyStateMachine" node_paths=PackedStringArray("player", "player_movement", "weapon_system", "land_sound")] script = ExtResource("12_fulsm") +acceleration = 25.0 player = NodePath("../..") player_movement = NodePath("../../PlayerMovement") -acceleration = 25.0 weapon_system = NodePath("../../WeaponSystem") land_sound = NodePath("../../LandAudio") @@ -8818,6 +8823,7 @@ animation_player = NodePath("../../AnimationPlayer") script = ExtResource("19_70eug") player = NodePath("..") player_input = NodePath("../PlayerInput") +jump_velocity = 12.0 [node name="WeaponSystem" type="Node" parent="." node_paths=PackedStringArray("animation_player", "camera", "player")] script = ExtResource("4_qlg0r") diff --git a/scripts/multiplayer/player_input.gd b/scripts/multiplayer/player_input.gd index 0f664d0..b234210 100644 --- a/scripts/multiplayer/player_input.gd +++ b/scripts/multiplayer/player_input.gd @@ -2,14 +2,16 @@ extends MultiplayerSynchronizer class_name PlayerInput +const SCOPE: int = 0b1 +const CROUCH: int = 0b10 +const WALK: int = 0b100 + #region SYNC @export var direction: Vector2 +@export var compressed_states: int #endregion -var crouching: bool = false -var scoping: bool = false -var walking: bool = false - +signal jumped signal drop signal switch_weapon(to_slot: StringName) signal fire_begin @@ -61,38 +63,42 @@ func _input(event: InputEvent) -> void: if event.is_action_pressed("plr_drop"): drop_on_server.rpc_id(1) + var crouching: bool = compressed_states & CROUCH + var walking: bool = compressed_states & WALK + var scoping: bool = compressed_states & SCOPE + if event.is_action_pressed("plr_crouch"): if ClientSettings.TOGGLE_CROUCH: crouch_on_server.rpc_id(1,crouching) - crouching = not crouching + compressed_states ^= CROUCH elif not crouching: - crouching = true + compressed_states |= CROUCH crouch_on_server.rpc_id(1,false) if event.is_action_released("plr_crouch") and not ClientSettings.TOGGLE_CROUCH and crouching: - crouching = false - crouch_on_server.rpc_id(1,false) + compressed_states &= ~CROUCH + crouch_on_server.rpc_id(1,true) if event.is_action_pressed("plr_walk"): if ClientSettings.TOGGLE_WALK: walk_on_server.rpc_id(1,walking) - walking = not walking + compressed_states ^= WALK elif not walking: - walking = true + compressed_states |= WALK walk_on_server.rpc_id(1,false) if event.is_action_released("plr_walk") and not ClientSettings.TOGGLE_WALK and walking: - walking = false - walk_on_server.rpc_id(1,false) + compressed_states &= ~WALK + walk_on_server.rpc_id(1,true) if event.is_action_pressed("plr_scope"): if ClientSettings.TOGGLE_SCOPE: scope_on_server.rpc_id(1,scoping) - scoping = not scoping + compressed_states ^= SCOPE elif not scoping: - scoping = true + compressed_states |= SCOPE scope_on_server.rpc_id(1,false) if event.is_action_released("plr_scope") and not ClientSettings.TOGGLE_SCOPE and scoping: - scoping = false - scope_on_server.rpc_id(1,false) + compressed_states &= ~SCOPE + scope_on_server.rpc_id(1,true) if event.is_action_pressed("plr_reload"): reload_on_server.rpc_id(1) @@ -101,6 +107,9 @@ func _input(event: InputEvent) -> void: interact_on_server.rpc_id(1,false) if event.is_action_released("plr_interact"): interact_on_server.rpc_id(1,true) + + if event.is_action_pressed("plr_jump"): + jump_on_server.rpc_id(1) @rpc("authority","call_local","reliable") func switch_on_server(slot: StringName) -> void: @@ -166,3 +175,8 @@ func interact_on_server(end: bool) -> void: interact_end.emit() else: interact_begin.emit() + +@rpc("authority","call_local","reliable") +func jump_on_server() -> void: + if not multiplayer.is_server(): return + jumped.emit() diff --git a/scripts/player/player_movement.gd b/scripts/player/player_movement.gd index 7052bc1..74dce84 100644 --- a/scripts/player/player_movement.gd +++ b/scripts/player/player_movement.gd @@ -4,6 +4,8 @@ class_name PlayerMovement @export var player: Player @export var player_input: PlayerInput + +@export var jump_velocity: float var disabled: bool func disable() -> void: @@ -24,3 +26,6 @@ func process_movement(max_speed: float,acceleration: float,deceleration: float,d else: player.velocity.x = move_toward(player.velocity.x, 0, deceleration*delta) player.velocity.z = move_toward(player.velocity.z, 0, deceleration*delta) + +func jump() -> void: + player.velocity.y = jump_velocity diff --git a/scripts/player/states/crouching.gd b/scripts/player/states/crouching.gd index 9bdff3f..5783cfd 100644 --- a/scripts/player/states/crouching.gd +++ b/scripts/player/states/crouching.gd @@ -8,22 +8,22 @@ extends State @export var stand_up_area: Area3D @export var player: Player @export var player_movement: PlayerMovement +@export var player_input: PlayerInput @export var animation_player: AnimationPlayer @export var crouch_time: float = 0.1 @export var weapon_system: WeaponSystem func enter() -> void: animation_player.play("crouch",-1,1/crouch_time) + player_input.crouch_end.connect(try_end_crouch) func exit() -> void: animation_player.play("crouch",-1,-1/crouch_time,true) + player_input.crouch_end.disconnect(try_end_crouch) func physics_update(delta: float) -> void: if not is_multiplayer_authority(): return - if Input.is_action_just_pressed("plr_jump") and player.is_on_floor() and toggle: - transition.emit("Stand") - return if not player.is_on_floor(): transition.emit("Fall") @@ -31,7 +31,6 @@ func physics_update(delta: float) -> void: player_movement.process_movement(max_speed * weapon_system.get_speed_modifier(),acceleration,deceleration,delta) -func state_input(event: InputEvent) -> void: - if (toggle == true and event.is_action_pressed("plr_crouch")) or (toggle == false and event.is_action_released("plr_crouch")): - if stand_up_area.has_overlapping_bodies() == false: - transition.emit("Stand") +func try_end_crouch() -> void: + if player.is_on_floor() and stand_up_area.has_overlapping_bodies() == false: + transition.emit("Stand") diff --git a/scripts/player/states/standing.gd b/scripts/player/states/standing.gd index f98fb74..31151a0 100644 --- a/scripts/player/states/standing.gd +++ b/scripts/player/states/standing.gd @@ -3,9 +3,9 @@ extends State @export var max_speed: float = 5.0 @export var acceleration: float = 2.0 @export var deceleration: float = 200.0 -@export var JUMP_VELOCITY: float = 4.5 @export var player: Player @export var player_movement: PlayerMovement +@export var player_input: PlayerInput @export var weapon_system: WeaponSystem @export var audio: MultiplayerAudio3D @export var step_delay: float @@ -14,18 +14,19 @@ extends State var step_time: float func enter() -> void: - pass + player_input.jumped.connect(on_jumped) + player_input.crouch_begin.connect(begin_crouch) + player_input.walk_begin.connect(begin_walk) func exit() -> void: + player_input.jumped.disconnect(on_jumped) + player_input.crouch_begin.disconnect(begin_crouch) + player_input.walk_begin.disconnect(begin_walk) step_time = 0 func physics_update(delta: float) -> void: if not is_multiplayer_authority(): return - if Input.is_action_just_pressed("plr_jump") and player.is_on_floor(): - player.velocity.y = JUMP_VELOCITY * sign(weapon_system.get_speed_modifier()) - transition.emit("Fall") - return if not player.is_on_floor(): transition.emit("Fall") @@ -38,9 +39,13 @@ func physics_update(delta: float) -> void: player_movement.process_movement(max_speed * weapon_system.get_speed_modifier(),acceleration,deceleration,delta) -func state_input(event: InputEvent) -> void: - if event.is_action_pressed("plr_crouch"): - transition.emit("Crouch") - - if event.is_action_pressed("plr_walk"): - transition.emit("Walk") +func on_jumped() -> void: + if player.is_on_floor(): + player_movement.jump() + transition.emit("Fall") + +func begin_walk() -> void: + transition.emit("Walk") + +func begin_crouch() -> void: + transition.emit("Crouch") diff --git a/scripts/player/states/walk.gd b/scripts/player/states/walk.gd index 579e7d1..8d31be5 100644 --- a/scripts/player/states/walk.gd +++ b/scripts/player/states/walk.gd @@ -6,21 +6,22 @@ extends State @export var JUMP_VELOCITY: float = 4.5 @export var player: Player @export var player_movement: PlayerMovement +@export var player_input: PlayerInput @export var weapon_system: WeaponSystem func enter() -> void: - pass + player_input.crouch_begin.connect(begin_crouch) + player_input.walk_end.connect(end_walk) + player_input.jumped.connect(on_jumped) func exit() -> void: - pass + player_input.crouch_begin.disconnect(begin_crouch) + player_input.walk_end.disconnect(end_walk) + player_input.jumped.disconnect(on_jumped) func physics_update(delta: float) -> void: if not is_multiplayer_authority(): return - if Input.is_action_just_pressed("plr_jump") and player.is_on_floor(): - player.velocity.y = JUMP_VELOCITY - transition.emit("Fall") - return if not player.is_on_floor(): transition.emit("Fall") @@ -28,9 +29,13 @@ func physics_update(delta: float) -> void: player_movement.process_movement(max_speed * weapon_system.get_speed_modifier(),acceleration,deceleration,delta) -func state_input(event: InputEvent) -> void: - if event.is_action_released("plr_walk"): - transition.emit("Stand") - - if event.is_action_pressed("plr_crouch"): - transition.emit("Crouch") +func on_jumped() -> void: + if player.is_on_floor(): + player_movement.jump() + transition.emit("Fall") + +func end_walk() -> void: + transition.emit("Stand") + +func begin_crouch() -> void: + transition.emit("Crouch") diff --git a/scripts/state_machine/machine.gd b/scripts/state_machine/machine.gd index 9735686..1773c5a 100644 --- a/scripts/state_machine/machine.gd +++ b/scripts/state_machine/machine.gd @@ -13,6 +13,7 @@ func _ready() -> void: else: push_warning("Child of state machine is not state") + current_state.enter() func on_transition_required(to: StringName): if is_multiplayer_authority() == false: