fixed bug where animation function wouldn't animate properly
This commit is contained in:
@@ -9,6 +9,7 @@ class_name Drone
|
||||
var dodge_duration_timer : Timer
|
||||
|
||||
func _ready() -> void:
|
||||
_animate(self.get_child(4,false),"walking")
|
||||
add_on_slots = 1
|
||||
for a in self.get_children() :
|
||||
if a.name == "DodgeDurationTimer" :
|
||||
@@ -19,6 +20,7 @@ func _ready() -> void:
|
||||
|
||||
func class_ability() -> float:
|
||||
#do dash
|
||||
animation_state_machine = MachineGlobals.regular_states.DASHING
|
||||
return dodge_cd
|
||||
|
||||
func listen_to_animation_signals(next_anim_state : MachineGlobals.regular_states) -> void:
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -43,8 +43,8 @@ enum irregular_states{
|
||||
}
|
||||
|
||||
enum look_direction{
|
||||
UP,
|
||||
DOWN,
|
||||
BACK,
|
||||
FRONT,
|
||||
LEFT,
|
||||
RIGHT
|
||||
}
|
||||
|
||||
@@ -11,9 +11,9 @@
|
||||
[ext_resource type="Texture2D" uid="uid://dnthmyuq5e54" path="res://Machines/Sprites/Drones/BaseDrone/BaseDroneLegsFrontWalk.png" id="7_fkyu2"]
|
||||
[ext_resource type="Texture2D" uid="uid://ctio2sfemdbag" path="res://Machines/Sprites/Drones/BaseDrone/BaseDroneLegsIdleFront.png" id="7_ogmjm"]
|
||||
[ext_resource type="Texture2D" uid="uid://dx2dpf8hvj8wa" path="res://Machines/Sprites/Drones/BaseDrone/BaseDroneHeadLeft.png" id="9_h54wi"]
|
||||
[ext_resource type="Texture2D" path="res://Machines/Sprites/Drones/BaseDrone/BaseDroneLegsWalkingSide.png" id="9_hvx52"]
|
||||
[ext_resource type="Texture2D" uid="uid://yi1h6ghnf5ey" path="res://Machines/Sprites/Drones/BaseDrone/BaseDroneLegsWalkingRight.png" id="10_20g50"]
|
||||
[ext_resource type="Texture2D" uid="uid://bb04dercpqua1" path="res://Machines/Sprites/Drones/BaseDrone/BaseDroneHeadRight.png" id="10_ua5ps"]
|
||||
[ext_resource type="Texture2D" uid="uid://cy6nappb0yf0x" path="res://Machines/Sprites/Drones/BaseDrone/BaseDroneLegsWalkingLeft.png" id="13_2wo2i"]
|
||||
|
||||
[sub_resource type="AtlasTexture" id="AtlasTexture_wbero"]
|
||||
atlas = ExtResource("2_1r2y7")
|
||||
@@ -144,27 +144,27 @@ atlas = ExtResource("7_fkyu2")
|
||||
region = Rect2(80, 5, 16, 11)
|
||||
|
||||
[sub_resource type="AtlasTexture" id="AtlasTexture_b1o6v"]
|
||||
atlas = ExtResource("9_hvx52")
|
||||
atlas = ExtResource("13_2wo2i")
|
||||
region = Rect2(0, 0, 16, 16)
|
||||
|
||||
[sub_resource type="AtlasTexture" id="AtlasTexture_8eqbb"]
|
||||
atlas = ExtResource("9_hvx52")
|
||||
atlas = ExtResource("13_2wo2i")
|
||||
region = Rect2(16, 0, 16, 16)
|
||||
|
||||
[sub_resource type="AtlasTexture" id="AtlasTexture_ope2v"]
|
||||
atlas = ExtResource("9_hvx52")
|
||||
atlas = ExtResource("13_2wo2i")
|
||||
region = Rect2(32, 0, 16, 16)
|
||||
|
||||
[sub_resource type="AtlasTexture" id="AtlasTexture_k67wn"]
|
||||
atlas = ExtResource("9_hvx52")
|
||||
atlas = ExtResource("13_2wo2i")
|
||||
region = Rect2(48, 0, 16, 16)
|
||||
|
||||
[sub_resource type="AtlasTexture" id="AtlasTexture_lxr7j"]
|
||||
atlas = ExtResource("9_hvx52")
|
||||
atlas = ExtResource("13_2wo2i")
|
||||
region = Rect2(64, 0, 16, 16)
|
||||
|
||||
[sub_resource type="AtlasTexture" id="AtlasTexture_5toxo"]
|
||||
atlas = ExtResource("9_hvx52")
|
||||
atlas = ExtResource("13_2wo2i")
|
||||
region = Rect2(80, 0, 16, 16)
|
||||
|
||||
[sub_resource type="AtlasTexture" id="AtlasTexture_gjxbl"]
|
||||
@@ -201,7 +201,18 @@ animations = [{
|
||||
"texture": SubResource("AtlasTexture_ny81s")
|
||||
}],
|
||||
"loop": true,
|
||||
"name": &"dbase_body_idle_up_and_down",
|
||||
"name": &"dbase_body_idle_back",
|
||||
"speed": 1.5
|
||||
}, {
|
||||
"frames": [{
|
||||
"duration": 1.0,
|
||||
"texture": SubResource("AtlasTexture_wbero")
|
||||
}, {
|
||||
"duration": 1.0,
|
||||
"texture": SubResource("AtlasTexture_ny81s")
|
||||
}],
|
||||
"loop": true,
|
||||
"name": &"dbase_body_idle_front",
|
||||
"speed": 1.5
|
||||
}, {
|
||||
"frames": [{
|
||||
@@ -410,7 +421,7 @@ animations = [{
|
||||
|
||||
[node name="BaseDrone" unique_id=872770085 instance=ExtResource("1_j7lnw")]
|
||||
script = ExtResource("2_njeil")
|
||||
model_name = &"Base"
|
||||
model_name = &"dbase"
|
||||
movement_speed = 150.0
|
||||
|
||||
[node name="Camera2D" parent="." index="1" unique_id=2079743221]
|
||||
@@ -421,12 +432,12 @@ position = Vector2(-1, -1)
|
||||
scale = Vector2(0.75, 0.875)
|
||||
sprite_frames = SubResource("SpriteFrames_wbero")
|
||||
animation = &"dbase_fueltank_idle"
|
||||
frame_progress = 0.6998867
|
||||
|
||||
[node name="Body" parent="." index="4" unique_id=1950083426]
|
||||
position = Vector2(-1, 1)
|
||||
sprite_frames = SubResource("SpriteFrames_wbero")
|
||||
animation = &"dbase_body_walking_right"
|
||||
frame_progress = 0.7253901
|
||||
animation = &"dbase_body_idle_back"
|
||||
|
||||
[node name="Head" parent="." index="5" unique_id=1860680538]
|
||||
position = Vector2(-6, 0)
|
||||
@@ -439,4 +450,6 @@ frame_progress = 0.95167845
|
||||
position = Vector2(0, 3)
|
||||
sprite_frames = SubResource("SpriteFrames_wbero")
|
||||
animation = &"dbase_legs_walking_left"
|
||||
frame_progress = 0.3296052
|
||||
frame_progress = 0.040086176
|
||||
|
||||
[connection signal="change_animation" from="." to="." method="listen_to_animation_signals"]
|
||||
|
||||
Reference in New Issue
Block a user