I have an input map called: Jetpackeqp (which is when I press e)
Here is the full code, There a non-repeated animation called: jetpack_eqp, I want to play it when I press ‘e’ on my keyboard but it does nothing. Could someone help?
extends CharacterBody2D
var speed = 200
const jump_velocity = -400
var direction = Vector2()
var jetpack_fuel = 100
var points = 0
var health = 100
var is_jetpack_eqp = false
@onready var sprite_2d = $Sprite2D
@onready var fuel_label = $Camera2D/jetpack_fuel
@onready var health_label = $Camera2D/main_health
@onready var health_bar = $Camera2D/health_bar
@onready var fuel_bar = $Camera2D/fuel_bar
var gravity = ProjectSettings.get_setting("physics/2d/default_gravity")
var animation = 'idle_no_jp'
func _is_jetpack_true():
if Input.is_action_pressed("Jetpackeqp"):
animation = 'jetpack_eqp'
func _ready():
health_bar.value = health
fuel_bar.value = jetpack_fuel
func damage(delta):
if Input.is_action_just_pressed('Damage'):
health -= 50 * delta
health_bar.value = health
#Function for moving
func _jetpacking(delta):
if Input.is_action_pressed("Jump") and jetpack_fuel > 0 and is_jetpack_eqp == true:
velocity.y = jump_velocity * 0.5
jetpack_fuel -= 10 * delta
animation = 'jetpacking'
else:
velocity.y += gravity * delta
if not is_on_floor() and is_jetpack_eqp == false:
animation = 'jumping_no_jp'
else:
animation = 'jumping_jp'
if not is_on_floor():
speed = 250
fuel_bar.value = jetpack_fuel
func _walking_n_running():
direction = Input.get_axis("GoLeft", "GoRight")
if direction != 0:
velocity.x = direction * speed
if speed > 200 and is_on_floor():
animation = "running_no_jp"
if speed <= 200 and is_on_floor():
animation = "walking_no_jp"
else:
velocity.x = move_toward(velocity.x, 0, 16)
if is_on_floor():
animation = "idle_no_jp"
func _jump(delta):
if is_on_floor() and Input.is_action_just_pressed("Jump"):
velocity.y = jump_velocity
animation = 'jumping_no_jp'
elif not is_on_floor():
_jetpacking(delta)
func _running():
if Input.is_action_pressed('Sprint') and is_on_floor():
speed = 280
else:
speed = 200
func _flip():
if Input.is_action_just_pressed('GoLeft'):
sprite_2d.flip_h = false
if Input.is_action_just_pressed('GoRight'):
sprite_2d.flip_h = true
#Function for moving end
func _physics_process(delta):
#movements
_is_jetpack_true()
_jump(delta)
_walking_n_running()
_running()
_flip()
move_and_slide()
#labelsetc_
sprite_2d.animation = animation
fuel_label.text = str(int(jetpack_fuel))
health_label.text = str(int(health))
#healthchanges
damage(delta)