Hey, everyone!
I recently started using godot, and for some reason, after jumping once, my player will not stop jumping.
Here's the script:
extends KinematicBody2D
const UP = Vector2(0, -1)
onready var slideShape: CollisionShape2D = $SlidingShape
onready var standShape: CollisionShape2D = $StandingShape
onready var animPlayer: AnimationPlayer = $Node2D/AnimationPlayer
onready var skeleton: Skeleton2D = $Node2D/Skeleton2D
onready var pivot: Node2D = $Node2D
onready var dashCooldown = $Timers/DashCooldown
onready var startingScale: Vector2 = pivot.scale
export var wallSlideSpeed = 120
export var wallSlideAccel = 10
export var accel = 30
export var speed = 400
var jumpWasPressed = false
var canJump = true
export var airSpeed = 400
export var maxJumps = 1
export var doubleJumps = 0
export var jumpForce = 600
export var gravity = 900
var velocity = Vector2()
func _ready():
randomize()
func _physics_process(delta: float) -> void:
var isInAir = !is_on_floor() and !is_on_wall() and !is_on_ceiling() and velocity.y < 0
if Input.get_action_strength("right"):
velocity.x = min(velocity.x + accel, speed)
if is_on_floor():
animPlayer.play("Run")
elif Input.get_action_strength("left"):
if is_on_floor():
animPlayer.play("Run")
velocity.x = max(velocity.x - accel, - speed)
else:
if is_on_floor():
animPlayer.play("Idle")
velocity.x = lerp(velocity.x,0,0.9)
velocity.y += gravity * delta
if Input.is_action_just_released("jump") and velocity.y <-200:
velocity.y = -100
if Input.is_action_just_pressed("jump"):
jumpWasPressed = true
if canJump == true:
velocity.y = -jumpForce
if is_on_wall() and Input.is_action_pressed("right"):
velocity.x = -speed
elif is_on_wall() and Input.is_action_pressed("left"):
velocity.x = speed
elif doubleJumps > 0:
velocity.y = -jumpForce
doubleJumps =doubleJumps - 1
if is_on_floor():
canJump = true
doubleJumps = maxJumps
if jumpWasPressed == true:
velocity.y = -jumpForce
elif !is_on_floor():
if doubleJumps > 0:
animPlayer.play("Jump")
elif !is_on_wall():
animPlayer.play("Jump")
if Input.is_action_pressed("dash"):
if dashCooldown.is_stopped():
airSpeed = 1600
speed = 1600
$Timers/DashTimer.start()
$Timers/DashCooldown.start()
else:
pass
if isInAir:
coyote_time()
pass
if is_on_floor():
canJump = true
doubleJumps = maxJumps
if is_on_wall() and (Input.is_action_pressed("right") or Input.is_action_pressed("left")):
canJump = true
if velocity.y >= 0:
velocity.y = min(velocity.y + wallSlideAccel, wallSlideSpeed)
animPlayer.play("WallSlide")
else:
velocity.y == gravity
else:
velocity.y == gravity
velocity = move_and_slide(velocity, UP)
if !is_zero_approx(velocity.x):
pivot.scale.x = sign(velocity.x) * startingScale.x
if velocity.y > 0 and !is_on_floor():
animPlayer.play("Fall")
func _on_Timer_timeout():
airSpeed = 400
speed = 400
func coyote_time():
yield(get_tree().create_timer(.2), "timeout")
canJump = false
pass
Thanks in advance!