diff --git a/components/explosive_damage_component.gd b/components/explosive_damage_component.gd
index 4bcdfc1..31b2a0e 100644
--- a/components/explosive_damage_component.gd
+++ b/components/explosive_damage_component.gd
@@ -1,15 +1,15 @@
# This file is part of open-fpsz.
-#
+#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
-#
+#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
-#
+#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see .
class_name ExplosiveDamageComponent extends Area3D
diff --git a/components/flag_carry_component.gd b/components/flag_carry_component.gd
index 5b0980e..3d6eac4 100644
--- a/components/flag_carry_component.gd
+++ b/components/flag_carry_component.gd
@@ -32,18 +32,16 @@ func _process(_delta):
_carried_flag.global_position = attachment.global_position
_carried_flag.global_rotation = attachment.global_rotation
-@rpc("call_local")
func _grab(flag : Flag):
if not _is_carrying():
flag.grab()
_carried_flag = flag
-@rpc("call_local")
-func _drop(throw_speed : float):
+func _release(inherited_velocity : Vector3, throw_speed : float):
if _is_carrying():
_carried_flag.drop()
_carried_flag.rotation_degrees.x = 0.0
- _carried_flag.linear_velocity = attachment.global_basis.z * throw_speed
+ _carried_flag.linear_velocity = inherited_velocity + (attachment.global_basis.z * throw_speed)
_carried_flag = null
func _is_carrying() -> bool:
@@ -51,10 +49,10 @@ func _is_carrying() -> bool:
func _sensor_on_body_entered(collider):
if collider is Flag:
- _grab.rpc(collider)
+ _grab(collider)
func drop():
- _drop.rpc(0.0)
+ _release(Vector3.ZERO, 0.0)
-func throw():
- _drop.rpc(max_throw_speed)
+func throw(inherited_velocity : Vector3):
+ _release(inherited_velocity, max_throw_speed)
diff --git a/entities/flag/flag.tscn b/entities/flag/flag.tscn
index a0dba63..c6ee466 100644
--- a/entities/flag/flag.tscn
+++ b/entities/flag/flag.tscn
@@ -1,7 +1,7 @@
[gd_scene load_steps=6 format=3 uid="uid://c88l3h0ph00c7"]
[ext_resource type="Script" path="res://entities/flag/flag.gd" id="1_y7d3d"]
-[ext_resource type="PackedScene" uid="uid://bftyiy6r0xaa3" path="res://entities/flag/assets/flag.glb" id="2_i78em"]
+[ext_resource type="PackedScene" uid="uid://d3l7fvbdg6m5g" path="res://entities/flag/assets/flag.glb" id="2_i78em"]
[sub_resource type="PhysicsMaterial" id="PhysicsMaterial_4ymrw"]
bounce = 0.5
diff --git a/entities/player/player.gd b/entities/player/player.gd
index 29ebb6d..a42a30c 100644
--- a/entities/player/player.gd
+++ b/entities/player/player.gd
@@ -19,6 +19,7 @@ enum PlayerState { PLAYER_ALIVE, PLAYER_DEAD }
@export_category("Parameters")
@export var ground_speed : float = 48 / 3.6 # m/s
@export var aerial_control_force : int = 400
+@export var jump_height : float = 2.0
@export var max_floor_angle : float = 60
@export_group("Jetpack")
@@ -32,7 +33,7 @@ enum PlayerState { PLAYER_ALIVE, PLAYER_DEAD }
@export_group("State")
@export var player_state = PlayerState.PLAYER_ALIVE
-@export var player_id = 1:
+@export var player_id : int = 1:
set(id):
player_id = id
$PlayerInput.set_multiplayer_authority(id)
@@ -60,16 +61,16 @@ var _jumping = false
func _ready():
energy_changed.connect(hud._on_energy_changed)
- health_component.health_changed.connect(hud._on_health_changed)
- health_component.health_changed.connect(iff._on_health_changed)
- health_component.health_changed.emit(health_component.health)
- health_component.health_zeroed.connect(_die)
if _is_first_person():
+ health_component.health_changed.connect(hud._on_health_changed)
camera.current = true
remove_child($ThirdPerson)
else:
- remove_child($HUD)
+ health_component.health_changed.connect(iff._on_health_changed)
+ remove_child(hud)
weapon.hide()
+ health_component.health_changed.emit(health_component.health)
+ health_component.health_zeroed.connect(die)
input.fired_primary.connect(_fire_primary)
input.jumped.connect(_jump)
input.throwed_flag.connect(_throw_flag)
@@ -96,7 +97,7 @@ func _jump():
_jumping = true
func _throw_flag():
- flag_carry_component.throw()
+ flag_carry_component.throw(linear_velocity)
func is_on_floor() -> bool:
if shape_cast.is_colliding():
@@ -176,8 +177,10 @@ func _physics_process(delta):
linear_velocity = lerp(linear_velocity, _direction * ground_speed, .1)
- if _jumping:
- linear_velocity.y = sqrt(2 * abs((mass * gravity * delta).y) * 1)
+func _integrate_forces(_state):
+ if is_on_floor() and _jumping:
+ var v = sqrt(2 * g * jump_height)
+ apply_central_impulse(Vector3(0, mass * v, 0))
_jumping = false
@@ -202,7 +205,7 @@ func _update_third_person_animations():
func _is_player_dead():
return player_state == PlayerState.PLAYER_DEAD
-func _die():
+func die():
player_state = PlayerState.PLAYER_DEAD
if _is_first_person():
animation_player.stop()
diff --git a/entities/player/player.tscn b/entities/player/player.tscn
index d17c267..e9ea190 100644
--- a/entities/player/player.tscn
+++ b/entities/player/player.tscn
@@ -207,6 +207,7 @@ mass = 75.0
physics_material_override = SubResource("PhysicsMaterial_clur0")
continuous_cd = true
script = ExtResource("1_mk68k")
+jump_height = 1.5
[node name="MeshInstance3D" type="MeshInstance3D" parent="."]
visible = false
diff --git a/entities/player/player_input.gd b/entities/player/player_input.gd
index 5e2d581..7780a4e 100644
--- a/entities/player/player_input.gd
+++ b/entities/player/player_input.gd
@@ -41,7 +41,7 @@ func _unhandled_input(event: InputEvent) -> void:
# retrieve mouse position relative to last frame
_mouse_position = event.relative * MOUSE_SENSITIVITY
-func _process(_delta):
+func _process(delta):
direction = Input.get_vector("left", "right", "forward", "backward")
if Input.is_action_just_pressed("jump_and_jet"):
_jump.rpc()
@@ -51,8 +51,6 @@ func _process(_delta):
_throw_flag.rpc()
jetting = Input.is_action_pressed("jump_and_jet")
skiing = Input.is_action_pressed("ski")
-
-func _physics_process(delta):
_update_camera(delta)
@rpc("call_local")
diff --git a/entities/target_dummy/target_dummy.gd b/entities/target_dummy/target_dummy.gd
index 87cf9f6..60b22ee 100644
--- a/entities/target_dummy/target_dummy.gd
+++ b/entities/target_dummy/target_dummy.gd
@@ -1,15 +1,15 @@
# This file is part of open-fpsz.
-#
+#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
-#
+#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
-#
+#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see .
class_name DummyTarget extends RigidBody3D
diff --git a/modes/multiplayer.tscn b/modes/multiplayer.tscn
index 8d9f249..e17e2c7 100644
--- a/modes/multiplayer.tscn
+++ b/modes/multiplayer.tscn
@@ -31,7 +31,6 @@ func start_server(port, nickname):
load_map.call_deferred(MAP)
- multiplayer.peer_connected.connect(add_player)
multiplayer.peer_disconnected.connect(remove_player)
if DisplayServer.get_name() != \"headless\":
@@ -69,7 +68,9 @@ func add_player(peer_id : int, nickname : String):
func remove_player(peer_id : int):
var node_name = str(peer_id)
if players.has_node(node_name):
- players.get_node(node_name).queue_free()
+ var player : Player = players.get_node(node_name)
+ player.die()
+ player.queue_free()
print(\"Peer `%s` disconnected\" % node_name)
@rpc(\"any_peer\")
diff --git a/weapons/space_gun/space_gun.gd b/weapons/space_gun/space_gun.gd
index 432d0cf..03e7766 100644
--- a/weapons/space_gun/space_gun.gd
+++ b/weapons/space_gun/space_gun.gd
@@ -1,15 +1,15 @@
# This file is part of open-fpsz.
-#
+#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
-#
+#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
-#
+#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see .
extends Node3D