Any help optimize code?

Godot Version

4.3

Question

Hi I was just curious about coding practices i have a bunch of Boolean variables to check for if a zombie should jump or not and its getting clutered like for example in my zombie script i have like 20 varaibles just for following the player, when to attack, when to jump and when to play death animations var health = 1
var speed = 200
var friendly = false
var player_chase = false
var player = null
var player_entered = false
var zombiey = position.y + 10
var prev_x_cord = 0
var stuck = false
var jump_force = -300 # Adjust this value as needed
var jump = false
var is_on_ground = false
var knockback_force = Vector2(300, -100) # Horizontal and vertical force for knockback if you need more info please let me know also i uploaded a video of my game on my channel if you want to see it better https://youtu.be/wPOShD0ih9c

Having many booleans is fine. Although can make code look complex.

You should look into the AnimationTree and it’s state machine, it’s specificly designed for this use case, and can replace most code.

1 Like