0 votes

extends KinematicBody2D

var charge = 0

func ready():
func _physics
func chargeFunc():
if Input.isactionpressed("attack") and charge > 4:
charge = charge + 0.5

var chargeBar = get_parent()
if charge == 4:
    chargeBar.texture = load("res://UI/FullCharge.png")
if charge == 3:
    chargeBar.texture = load("res://UI/Charged3.png")
if charge == 2:
    chargeBar.texture = load("res://UI/Charged2.png")
if charge == 1:
    chargeBar.texture = load("res://UI/Charged1.png")
if charge == 0:
    chargeBar.texture = load("res://UI/EmptyCharge.png")

if Input.is_action_just_released("attack"):
    charge = 0
Godot version Godot Engine v3.3.stable.official
in Engine by (19 points)

1 Answer

0 votes

It looks like it's impossible for charge to ever be greater than 0 since it's only incremented when charge is greater than 4.

Also, I think you should look into using match statements instead of having many separate if statements. Also, I'm not sure if you want to run this code in _physics_process. It sounds like it might increment the charge counter too quickly? Maybe consider using a Timer?

by (7,190 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.