fixed bug where animation function wouldn't animate properly

This commit is contained in:
2026-02-27 17:13:20 +01:00
parent 602e5595ca
commit 0a474dde90
13 changed files with 144 additions and 105 deletions

View File

@@ -9,6 +9,7 @@ extends CharacterBody2D
@export var movement_speed : float
signal change_animation(anim_to_change_to)
var animation_state_machine : MachineGlobals.regular_states
var last_state : MachineGlobals.regular_states
var look_dir : MachineGlobals.look_direction
var effects : Array
var add_on_slots : int
@@ -25,33 +26,40 @@ var current_fuel_in_tank : float
@abstract func listen_to_animation_signals(next_anim_state : MachineGlobals.regular_states) -> void
func _ready() -> void:
connect("change_animation",listen_to_animation_signals)
func interact() -> void :
pass
func _physics_process(delta: float) -> void:
DebugGlobal.set_debug_info("State machine:",str(MachineGlobals.regular_states.keys()[animation_state_machine]))
_movement(delta)
_ability_process(delta)
_action_process(delta)
_animate_according_to_state_machine()
move_and_slide()
func _animate_according_to_state_machine() -> void :
DebugGlobal.set_debug_info("last state: ", str(MachineGlobals.regular_states.keys()[last_state]))
if animation_state_machine != last_state :
print_debug("Emitting signal to change animation to "+str(MachineGlobals.regular_states.keys()[animation_state_machine]))
change_animation.emit(animation_state_machine)
last_state = animation_state_machine
func _movement(delta: float) -> void :
DebugGlobal.set_debug_info("Velocity", self.velocity )
DebugGlobal.set_debug_info("Velocity", self.velocity)
DebugGlobal.set_debug_info("Looking ", MachineGlobals.look_direction.keys()[look_dir ])
var input_direction = Input.get_vector("move_left", "move_right", "move_up", "move_down")
self.velocity = input_direction * movement_speed
if self.velocity != Vector2.ZERO && animation_state_machine in [MachineGlobals.regular_states.IDLING,MachineGlobals.regular_states.INTERACTING] :
animation_state_machine = MachineGlobals.regular_states.WALKING
if self.velocity.y < 0 :
look_dir = MachineGlobals.look_direction.UP
look_dir = MachineGlobals.look_direction.BACK
elif self.velocity.y > 0 :
look_dir = MachineGlobals.look_direction.DOWN
look_dir = MachineGlobals.look_direction.FRONT
elif self.velocity.x > 0 :
look_dir = MachineGlobals.look_direction.RIGHT
elif self.velocity.x < 0 :
look_dir = MachineGlobals.look_direction.LEFT
else :
elif velocity.length() == 0 :
animation_state_machine = MachineGlobals.regular_states.IDLING
func _action_process(delta:float) -> void :
@@ -77,5 +85,9 @@ func _get_body_parts() -> Array :
func _animate(b : BodyPart, animation_type : String) -> void :
for anim_name : String in b.sprite_frames.get_animation_names() :
if anim_name.contains(animation_type) && anim_name.contains(model_name) && anim_name.contains(str(MachineGlobals.look_direction.keys()[look_dir])) :
#print_debug("Trying to play animation for: "+model_name+"_"+b.name+"_"+animation_type+"_"+str(MachineGlobals.look_direction.keys()[look_dir]))
print_debug(b.sprite_frames.get_animation_names())
print_debug("Anim name: "+anim_name+" Anim type: "+str(animation_type)+" Model name: "+str(model_name)+" Look direction: "+str(MachineGlobals.look_direction.keys()[look_dir])+" body part: "+b.name)
if anim_name.containsn(animation_type) && anim_name.containsn(model_name) && anim_name.containsn(str(MachineGlobals.look_direction.keys()[look_dir])) && anim_name.containsn(b.name) :
print_debug("Animation name found: "+anim_name)
b.play(anim_name)