🐛 Fix network issues affecting flag and player movement

This commit is contained in:
Squinty 2024-04-17 16:07:24 +00:00
parent 63e39bbe15
commit 503e15b591
9 changed files with 34 additions and 33 deletions

View file

@ -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()

View file

@ -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

View file

@ -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")