fix throwing

This commit is contained in:
anyreso 2026-03-16 10:43:26 -04:00
parent e984e905e6
commit bd06afc823
2 changed files with 7 additions and 4 deletions

View file

@ -14,6 +14,7 @@ visible = false
script = ExtResource("1_3kspm")
[node name="ThrowTimer" type="Timer" parent="." unique_id=1484924086]
wait_time = 2.0
one_shot = true
[node name="ThrowForce" type="TextureProgressBar" parent="." unique_id=1819816062]

View file

@ -32,7 +32,7 @@ var flag:Flag
func _process(_delta: float) -> void:
if is_visible_in_tree() and not timer.is_stopped():
var time_elapsed: float = timer.wait_time - timer.time_left
texture_progress.value = time_elapsed / timer.wait_time * 100
texture_progress.value = time_elapsed / (timer.wait_time / 2) * 100
## This method grabs a [Flag] which set the mesh visible, holds a reference to it
## and emits the [Flag.grabbed] signal to handle further state changes
@ -50,19 +50,20 @@ func drop() -> void:
if owner is RigidBody3D:
flag.global_rotation.y = -flag.global_basis.z.dot(owner.linear_velocity)
flag.apply_impulse.call_deferred(flag.mass * owner.linear_velocity)
hide()
flag.dropped.emit(self)
flag = null
## This method displays throw force progress on the [HUD] of a client and upon release
## it throws the [Flag]. It has no effect when holding no flag or flag is [member Flag.FlagState.TAKEN]
## it throws the [Flag]. It has no effect when holding no flag or flag is not [member Flag.FlagState.TAKEN]
func throw(pressed:bool) -> void:
if flag and flag.state == flag.FlagState.TAKEN:
if pressed:
timer.start()
texture_progress.visible = true
timer.timeout.connect(func() -> void: texture_progress.visible = false)
else:
if timer.is_stopped():
texture_progress.visible = false
return
var time_elapsed:float = timer.wait_time - timer.time_left
timer.stop()
@ -71,7 +72,8 @@ func throw(pressed:bool) -> void:
var pumped_force:float = clampf(time_elapsed / timer.wait_time * throw_force, 6., throw_force)
var throw_velocity:Vector3 = -global_basis.z * pumped_force
if owner:
if owner is Player:
# player has camera and linear velocity
flag.global_position = owner.global_position
flag.global_rotation.y = owner.camera.global_rotation.y
throw_velocity = -owner.camera.global_basis.z * pumped_force + owner.linear_velocity