Godot Version
4.1.3.stable
Question
Hi IndieQuantum here,
I need a little help with properly making a stamina system for my player.
The player can hold onto a wall, but will lose stamina and fall or slide down the wall. I tried to implement this in my player script but I does not work.
Here is the script (sorry for the messy script):
var JumpHeight = -320
var VariableJumpHeight = -60
var DoubleJumpHeight = -300
var Speed = 100
var Gravity = 250
var Acceleration = 90
var DoubleJump = 1
var BufferedJump = false
var CoyoteJump = false
var WallSlideFriction = 300
var IsWallSliding = false
var StaminaDepleted = false
func _physics_process(_delta):
var Friction = false
#Gravity------------------------------------------------------------------------
velocity.y = min(velocity.y + 22.5, Gravity)
#Movement-----------------------------------------------------------------------
if Input.is_action_pressed(“move_right”):
velocity.x = min(velocity.x + Acceleration, Speed)
$AnimatedSprite2D.play(“run”)
$AnimatedSprite2D.flip_h = false
elif Input.is_action_pressed(“move_left”):
velocity.x = max(velocity.x - Acceleration, -Speed)
$AnimatedSprite2D.play(“run”)
$AnimatedSprite2D.flip_h = true
else:
Friction = true
$AnimatedSprite2D.play(“idle”)
#Jump, Double Jump, Jump Buffer-------------------------------------------------
if Input.is_action_just_released(“jump”) and velocity.y < VariableJumpHeight:
velocity.y = VariableJumpHeight
if is_on_floor() or CoyoteJump:
DoubleJump = 1
if Input.is_action_just_pressed(“jump”) or BufferedJump:
velocity.y = JumpHeight
BufferedJump = false
if Friction == true:
velocity.x = lerp(float(velocity.x), 0.0, 0.4)
else:
if Input.is_action_just_pressed(“jump”) and DoubleJump > 0:
velocity.y = DoubleJumpHeight
DoubleJump -= 1
if Input.is_action_just_pressed(“jump”):
BufferedJump = true
$JumpBufferTimer.start()
if Friction == true:
velocity.x = lerp(float(velocity.x), 0.0, 0.07)
if velocity.y > 0 and not is_on_floor():
$AnimatedSprite2D.play(“fall”)
$AnimatedSprite2D.visible = true
$AnimatedSprite2D2.visible = false
elif velocity.y < 0:
if DoubleJump > 0:
$AnimatedSprite2D.play(“jump”)
else:
$AnimatedSprite2D2.play(“double_jump”)
$AnimatedSprite2D2.visible = true
$AnimatedSprite2D.visible = false
#Wall Hold----------------------------------------------------------------------
if Input.is_action_pressed(“wall_grab”) and is_on_wall():
if $LeftWallDetector.is_colliding() and StaminaDepleted:
position += Vector2.LEFT
$AnimatedSprite2D.play(“wall_jump”)
$AnimatedSprite2D.flip_h = true
DoubleJump = 1
velocity.y = min(velocity.y + 0, 0)
DoubleJumpHeight = 0
JumpHeight = 0
velocity.x = 0
$StaminaTimer.start()
elif $RightWallDetector.is_colliding() and StaminaDepleted:
position += Vector2.RIGHT
$AnimatedSprite2D.play(“wall_jump”)
$AnimatedSprite2D.flip_h = false
DoubleJump = 1
velocity.y = min(velocity.y + 0, 0)
DoubleJumpHeight = 0
JumpHeight = 0
velocity.x = 0
$StaminaTimer.start()
else:
Gravity = 250
DoubleJumpHeight = -300
JumpHeight = -320
#Wall Slide---------------------------------------------------------------------
if is_on_wall() and not is_on_floor():
if Input.is_action_pressed(“move_left”) or Input.is_action_pressed(“move_right”):
IsWallSliding = true
$AnimatedSprite2D.play(“wall_jump”)
Gravity = 50
DoubleJumpHeight = 0
else:
IsWallSliding = false
var was_on_floor = is_on_floor()
#Overall Movement---------------------------------------------------------------
move_and_slide()
#Coyote Timer-------------------------------------------------------------------
var just_left_ground = not is_on_floor() and was_on_floor
if just_left_ground and velocity.y >= 0:
CoyoteJump = true
$CoyoteJumpTimer.start()
func _on_jump_buffer_timer_timeout():
BufferedJump = false
func _on_coyote_jump_timer_timeout():
CoyoteJump = false
func _on_stamina_timer_timeout():
StaminaDepleted = false