Merge pull request #40 from tokc/tokc/jetpack

Reimplement jetpack based on earlier code from before rework.
pull/42/head
unfa 2021-03-30 20:08:29 +02:00 committed by GitHub
commit 969356dc2f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 63 additions and 4 deletions

View File

@ -28,11 +28,12 @@ var jump_timeout = 0.0
var floor_normal = Vector3.UP
var was_on_floor = false
const JETPACK_FUEL_MAX = 1
const JETPACK_REFILL_RATE = 1/5
const JETPACK_THRUST = 1500
const JETPACK_FUEL_MAX = 0.6
const JETPACK_REFILL_RATE = 0.2
const JETPACK_THRUST = 25
var jetpack_active = false # is the jetpack active?
var jetpack_used = false # Is the jetpack recharging?
var jetpack_fuel = JETPACK_FUEL_MAX # max fuel (in seconds)
#onready var sfx_foosteps = [$"Sounds/Footstep-Concrete-01",
@ -103,6 +104,63 @@ remote func jump():
$Sounds/Jump.play()
weapon_bob_anim.travel("Jump")
func jetpack(delta):
# Swap these to try the different versions of the jetpack.
jetpack_grounded(delta)
#jetpack_empty(delta)
func jetpack_empty(delta):
debug.text = "JP fuel: %s\nJP active: %s\nJP used: %s\nJP sound: %s" % [
jetpack_fuel, jetpack_active, jetpack_used, !$Sounds/Jetpack.stream_paused
]
# Enable jetpack when it is fully charged.
if jetpack_fuel > (JETPACK_FUEL_MAX - 0.001):
jetpack_used = false
# Disable jetpack when it is empty.
elif jetpack_fuel <= 0 and not jetpack_active:
jetpack_used = true
if jetpack_active and not jetpack_used and jetpack_fuel > 0:
velocity.y += JETPACK_THRUST * delta
jetpack_fuel -= delta
$Sounds/Jetpack.stream_paused = false
else:
$Sounds/Jetpack.stream_paused = true
# Only charge when fully empty.
if jetpack_used:
jetpack_fuel = clamp(
jetpack_fuel + JETPACK_REFILL_RATE * delta,
0.0,
JETPACK_FUEL_MAX
)
# Charge when grounded variant.
func jetpack_grounded(delta):
debug.text = "JP fuel: %s\nJP active: %s\nJP sound: %s" % [
jetpack_fuel, jetpack_active, !$Sounds/Jetpack.stream_paused
]
# Only charge when grounded.
if is_on_floor:
jetpack_fuel = clamp(
jetpack_fuel + JETPACK_REFILL_RATE * delta,
0.0,
JETPACK_FUEL_MAX
)
$Sounds/Jetpack.stream_paused = true
# Only use jetpack in the air.
else:
if jetpack_active and jetpack_fuel > 0:
velocity.y += JETPACK_THRUST * delta
jetpack_fuel -= delta
$Sounds/Jetpack.stream_paused = false
else:
$Sounds/Jetpack.stream_paused = true
remote func mouselook_abs(x, y):
camera.rotation.x = x
rotation.y = y
@ -125,6 +183,7 @@ func _physics_process(delta):
walk(delta)
fall(delta)
jetpack(delta)
var movement_vector = Vector3()
if jump_timeout > 0:
@ -294,7 +353,7 @@ func _input(event):
if event.is_action_pressed("MoveJetpack"):
jetpack_active = true
else:
if event.is_action_released("MoveJetpack"):
jetpack_active = false
if event.is_action_pressed("WeaponPrimary"):