Fixed jetpack effects synchronisation

remotes/1708764123287856048/tmp_refs/heads/announcer
Jan Heemstra 2021-04-07 22:54:52 +02:00
parent 890857946c
commit f3b1904702
2 changed files with 28 additions and 15 deletions

View File

@ -33,6 +33,7 @@ const JETPACK_REFILL_RATE = 0.2
const JETPACK_THRUST = 25 const JETPACK_THRUST = 25
var jetpack_active = false # is the jetpack active? var jetpack_active = false # is the jetpack active?
var jetpack_fireing = false # Is the jetpack fireing?
var jetpack_used = false # Is the jetpack recharging? var jetpack_used = false # Is the jetpack recharging?
var jetpack_fuel = JETPACK_FUEL_MAX # max fuel (in seconds) var jetpack_fuel = JETPACK_FUEL_MAX # max fuel (in seconds)
@ -109,13 +110,20 @@ remote func jump():
func jetpack(delta): func jetpack(delta):
# Swap these to try the different versions of the jetpack. # Swap these to try the different versions of the jetpack.
jetpack_grounded(delta) #jetpack_grounded(delta)
#jetpack_empty(delta) #jetpack_empty(delta)
# activate visual jetpack effects when sound is playing: # activate visual jetpack effects when sound is playing:
$Effects/JetpackFlame.emitting = ! $Sounds/Jetpack.stream_paused $Sounds/Jetpack.stream_paused = !jetpack_fireing
$Effects/JetpackSmoke.emitting = ! $Sounds/Jetpack.stream_paused
$Effects/JetpackLight.visible = ! $Sounds/Jetpack.stream_paused $Effects/JetpackFlame.emitting = jetpack_fireing
$Effects/JetpackSmoke.emitting = jetpack_fireing
$Effects/JetpackLight.visible = jetpack_fireing
#print(get_tree().get_network_unique_id())
#$Effects/JetpackFlame.emitting = ! $Sounds/Jetpack.stream_paused
#$Effects/JetpackSmoke.emitting = ! $Sounds/Jetpack.stream_paused
#$Effects/JetpackLight.visible = ! $Sounds/Jetpack.stream_paused
func jetpack_empty(delta): func jetpack_empty(delta):
debug.text = "JP fuel: %s\nJP active: %s\nJP used: %s\nJP sound: %s" % [ debug.text = "JP fuel: %s\nJP active: %s\nJP used: %s\nJP sound: %s" % [
@ -159,16 +167,17 @@ func jetpack_grounded(delta):
JETPACK_FUEL_MAX JETPACK_FUEL_MAX
) )
$Sounds/Jetpack.stream_paused = true jetpack_fireing = false
# Only use jetpack in the air. # Only use jetpack in the air.
else: else:
if jetpack_active and jetpack_fuel > 0: if jetpack_active and jetpack_fuel > 0:
velocity.y += JETPACK_THRUST * delta velocity.y += JETPACK_THRUST * delta
jetpack_fuel -= delta jetpack_fuel -= delta
$Sounds/Jetpack.stream_paused = false jetpack_fireing = true
else: else:
$Sounds/Jetpack.stream_paused = true jetpack_fireing = false
remote func mouselook_abs(x, y): remote func mouselook_abs(x, y):
camera.rotation.x = x camera.rotation.x = x
@ -192,7 +201,7 @@ func _physics_process(delta):
walk(delta) walk(delta)
fall(delta) fall(delta)
jetpack(delta) jetpack_grounded(delta)
var movement_vector = Vector3() var movement_vector = Vector3()
if jump_timeout > 0: if jump_timeout > 0:
@ -359,17 +368,19 @@ func _input(event):
var rel = event.relative var rel = event.relative
mouselook(rel) mouselook(rel)
# Jump
# Jump
if event.is_action_pressed("MoveJump"): if event.is_action_pressed("MoveJump"):
rpc("jump") rpc("jump")
jump() jump()
# Jetpack
if event.is_action_pressed("MoveJetpack"): if event.is_action_pressed("MoveJetpack"):
jetpack_active = true rpc("set_jetpack_active", true)
if event.is_action_released("MoveJetpack"): if event.is_action_released("MoveJetpack"):
jetpack_active = false rpc("set_jetpack_active", false)
# Weapon
if event.is_action_pressed("WeaponPrimary"): if event.is_action_pressed("WeaponPrimary"):
shoot() shoot()
if event.is_action_pressed("WeaponReload"): if event.is_action_pressed("WeaponReload"):
@ -380,6 +391,8 @@ func _input(event):
if event.is_action_pressed("WeaponPrev"): if event.is_action_pressed("WeaponPrev"):
rpc("switch_to_prev_weapon") rpc("switch_to_prev_weapon")
sync func set_jetpack_active(active):
jetpack_active = active
func set_local_player(): func set_local_player():
set_network_master(get_tree().get_network_unique_id()) set_network_master(get_tree().get_network_unique_id())
@ -417,5 +430,5 @@ func _ready():
#$Sounds/Jetpack.stream. #$Sounds/Jetpack.stream.
# Called every frame. 'delta' is the elapsed time since the previous frame. # Called every frame. 'delta' is the elapsed time since the previous frame.
#func _process(delta): func _process(delta):
# pass jetpack(delta)

View File

@ -220,7 +220,7 @@ script = ExtResource( 8 )
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1.53592, -0.0651628 ) transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1.53592, -0.0651628 )
[node name="Hand" type="Spatial" parent="Camera"] [node name="Hand" type="Spatial" parent="Camera"]
transform = Transform( -4.37114e-08, 0, -1, 0, 1, 0, 1, 0, -4.37114e-08, 0.335, -0.397075, -0.559 ) transform = Transform( -4.37114e-08, 0, -1, 0, 1, 0, 1, 0, -4.37114e-08, 0.335, -0.392394, -0.559 )
[node name="WeaponBobAnimationTree" type="AnimationTree" parent="Camera/Hand"] [node name="WeaponBobAnimationTree" type="AnimationTree" parent="Camera/Hand"]
tree_root = SubResource( 12 ) tree_root = SubResource( 12 )