Use Input Dotproduct based Animation Choosing for Player
This commit is contained in:
parent
006e1046a3
commit
11e59ce070
2 changed files with 16 additions and 16 deletions
|
@ -41,7 +41,7 @@
|
|||
[ext_resource type="StyleBox" uid="uid://0jfr1uwuog0s" path="res://Assets/UI/Slider/v/background.tres" id="39_dl1e4"]
|
||||
[ext_resource type="FontFile" uid="uid://dqdeftjkwxe64" path="res://Assets/Fonts/Dogica/dogicapixel.ttf" id="40_bmcvq"]
|
||||
|
||||
[sub_resource type="Image" id="Image_avfxn"]
|
||||
[sub_resource type="Image" id="Image_fjlcl"]
|
||||
data = {
|
||||
"data": PackedByteArray(255, 255, 255, 0, 255, 255, 255, 64, 255, 255, 255, 64, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 64, 255, 255, 255, 64, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 64, 255, 255, 255, 64, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 64, 255, 255, 255, 64, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 64, 255, 255, 255, 64, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 64, 255, 255, 255, 64, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 64, 255, 255, 255, 64, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 64, 255, 255, 255, 64, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 64, 255, 255, 255, 64, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 64, 255, 255, 255, 64, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 64, 255, 255, 255, 64, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 64, 255, 255, 255, 64, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 64, 255, 255, 255, 64, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 64, 255, 255, 255, 64, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 64, 255, 255, 255, 64, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 64, 255, 255, 255, 64, 255, 255, 255, 0),
|
||||
"format": "RGBA8",
|
||||
|
@ -51,7 +51,7 @@ data = {
|
|||
}
|
||||
|
||||
[sub_resource type="ImageTexture" id="ImageTexture_g5bup"]
|
||||
image = SubResource("Image_avfxn")
|
||||
image = SubResource("Image_fjlcl")
|
||||
|
||||
[sub_resource type="StyleBoxEmpty" id="StyleBoxEmpty_sj7h5"]
|
||||
|
||||
|
|
|
@ -25,20 +25,20 @@ func update_player_movement(delta : float):
|
|||
# Update Objects Physics calculations
|
||||
self.move_and_slide()
|
||||
pass
|
||||
|
||||
|
||||
func update_player_animation():
|
||||
var move_vector = get_move_input_vector()
|
||||
match move_vector:
|
||||
match get_move_input_vector():
|
||||
Vector2.ZERO: animation_player.play("Idle")
|
||||
Vector2.LEFT: animation_player.play("MoveLeft")
|
||||
Vector2.RIGHT: animation_player.play("MoveRight")
|
||||
Vector2.UP: animation_player.play("MoveUp")
|
||||
Vector2.DOWN: animation_player.play("MoveDown")
|
||||
_: handle_diagonal_animations(move_vector)
|
||||
pass
|
||||
|
||||
func handle_diagonal_animations(dir : Vector2):
|
||||
if (dir.y > 0 and dir.x < 0) or (dir.y < 0 and dir.x < 0): animation_player.play("MoveLeft")
|
||||
elif (dir.y > 0 and dir.x > 0) or (dir.y < 0 and dir.x > 0): animation_player.play("MoveRight")
|
||||
else: animation_player.play("Idle")
|
||||
_:
|
||||
var left_dot = Vector2.LEFT.dot(self.velocity)
|
||||
var right_dot = Vector2.RIGHT.dot(self.velocity)
|
||||
var up_dot = Vector2.UP.dot(self.velocity)
|
||||
var down_dot = Vector2.DOWN.dot(self.velocity)
|
||||
|
||||
var max_dot = maxf(left_dot, maxf(right_dot, maxf(up_dot, down_dot)))
|
||||
match max_dot:
|
||||
left_dot: animation_player.play("MoveLeft")
|
||||
right_dot: animation_player.play("MoveRight")
|
||||
up_dot: animation_player.play("MoveUp")
|
||||
down_dot: animation_player.play("MoveDown")
|
||||
pass
|
||||
|
|
Reference in a new issue