Added velocity based bunny animations but it does not feel too good

This commit is contained in:
AXVIII3 2023-04-11 01:15:25 +05:30
parent c455cdecb1
commit 502820fc56
4 changed files with 315 additions and 15 deletions

View file

@ -1,4 +1,4 @@
[gd_scene load_steps=5 format=3 uid="uid://cpl4tllohhyel"]
[gd_scene load_steps=12 format=3 uid="uid://cpl4tllohhyel"]
[ext_resource type="Script" path="res://Scripts/EntitySystem/Bunny.gd" id="1_1kj2b"]
[ext_resource type="Texture2D" uid="uid://df2fluk0dlqar" path="res://Assets/Sprites/Bunny/bad_bunny_spritesheet.png" id="2_v8p70"]
@ -8,10 +8,119 @@
[sub_resource type="CircleShape2D" id="CircleShape2D_itvjj"]
radius = 14.0
[node name="Bunny" type="CharacterBody2D" node_paths=PackedStringArray("agent")]
[sub_resource type="Animation" id="Animation_l8j6b"]
resource_name = "MoveLeft"
length = 0.5
loop_mode = 1
tracks/0/type = "value"
tracks/0/imported = false
tracks/0/enabled = true
tracks/0/path = NodePath("Sprite2D:frame")
tracks/0/interp = 1
tracks/0/loop_wrap = true
tracks/0/keys = {
"times": PackedFloat32Array(0, 0.1, 0.2, 0.3, 0.4),
"transitions": PackedFloat32Array(1, 1, 1, 1, 1),
"update": 1,
"values": [5, 6, 7, 8, 9]
}
[sub_resource type="Animation" id="Animation_45lfy"]
resource_name = "MoveUp"
length = 0.5
loop_mode = 1
tracks/0/type = "value"
tracks/0/imported = false
tracks/0/enabled = true
tracks/0/path = NodePath("Sprite2D:frame")
tracks/0/interp = 1
tracks/0/loop_wrap = true
tracks/0/keys = {
"times": PackedFloat32Array(0, 0.1, 0.2, 0.3, 0.4),
"transitions": PackedFloat32Array(1, 1, 1, 1, 1),
"update": 1,
"values": [15, 16, 17, 18, 19]
}
[sub_resource type="Animation" id="Animation_olc18"]
resource_name = "MoveDown"
length = 0.5
loop_mode = 1
tracks/0/type = "value"
tracks/0/imported = false
tracks/0/enabled = true
tracks/0/path = NodePath("Sprite2D:frame")
tracks/0/interp = 1
tracks/0/loop_wrap = true
tracks/0/keys = {
"times": PackedFloat32Array(0, 0.1, 0.2, 0.3, 0.4),
"transitions": PackedFloat32Array(1, 1, 1, 1, 1),
"update": 1,
"values": [0, 1, 2, 3, 4]
}
[sub_resource type="Animation" id="Animation_agj62"]
resource_name = "MoveRight"
length = 0.5
loop_mode = 1
tracks/0/type = "value"
tracks/0/imported = false
tracks/0/enabled = true
tracks/0/path = NodePath("Sprite2D:frame")
tracks/0/interp = 1
tracks/0/loop_wrap = true
tracks/0/keys = {
"times": PackedFloat32Array(0, 0.1, 0.2, 0.3, 0.4),
"transitions": PackedFloat32Array(1, 1, 1, 1, 1),
"update": 1,
"values": [10, 11, 12, 13, 14]
}
[sub_resource type="Animation" id="Animation_6br4g"]
resource_name = "Idle"
tracks/0/type = "value"
tracks/0/imported = false
tracks/0/enabled = true
tracks/0/path = NodePath("Sprite2D:frame")
tracks/0/interp = 1
tracks/0/loop_wrap = true
tracks/0/keys = {
"times": PackedFloat32Array(0),
"transitions": PackedFloat32Array(1),
"update": 1,
"values": [0]
}
[sub_resource type="Animation" id="Animation_mp212"]
length = 0.001
tracks/0/type = "value"
tracks/0/imported = false
tracks/0/enabled = true
tracks/0/path = NodePath("Sprite2D:frame")
tracks/0/interp = 1
tracks/0/loop_wrap = true
tracks/0/keys = {
"times": PackedFloat32Array(0),
"transitions": PackedFloat32Array(1),
"update": 1,
"values": [0]
}
[sub_resource type="AnimationLibrary" id="AnimationLibrary_uuf00"]
_data = {
"Idle": SubResource("Animation_6br4g"),
"MoveDown": SubResource("Animation_olc18"),
"MoveLeft": SubResource("Animation_l8j6b"),
"MoveRight": SubResource("Animation_agj62"),
"MoveUp": SubResource("Animation_45lfy"),
"RESET": SubResource("Animation_mp212")
}
[node name="Bunny" type="CharacterBody2D" node_paths=PackedStringArray("animation_player", "agent")]
collision_layer = 4
collision_mask = 15
script = ExtResource("1_1kj2b")
animation_player = NodePath("BunnyAnimator")
agent = NodePath("NavigationAgent")
[node name="Sprite2D" type="Sprite2D" parent="."]
@ -33,5 +142,10 @@ collision_mask = 4
[node name="CollisionShape2D" type="CollisionShape2D" parent="Area2D"]
shape = SubResource("CircleShape2D_itvjj")
[node name="BunnyAnimator" type="AnimationPlayer" parent="."]
libraries = {
"": SubResource("AnimationLibrary_uuf00")
}
[connection signal="body_entered" from="Area2D" to="." method="_on_collision"]
[connection signal="body_exited" from="Area2D" to="." method="_of_collision"]

173
Scenes/GameBunnyAnims.tscn Normal file

File diff suppressed because one or more lines are too long

View file

@ -1,22 +1,22 @@
[gd_scene load_steps=14 format=3 uid="uid://4fysk8vaw3e1"]
[ext_resource type="Script" path="res://Scripts/UI/MainMenuManager.gd" id="1_qepq0"]
[ext_resource type="Texture2D" uid="uid://tjxkew3m4v8m" path="res://Assets/Sprites/Easter Egg/Shadow.png" id="2_8o6th"]
[ext_resource type="PackedScene" uid="uid://c4btepmue6d7p" path="res://Scenes/Game.tscn" id="2_28004"]
[ext_resource type="Texture2D" uid="uid://daat37cyg0go5" path="res://Assets/Sprites/Easter Egg/Egg 3.png" id="3_1e3fe"]
[ext_resource type="Texture2D" uid="uid://tjxkew3m4v8m" path="res://Assets/Sprites/Start Menu Old/Easter Egg/Shadow.png" id="2_8o6th"]
[ext_resource type="PackedScene" uid="uid://dkcl1ycmxpilw" path="res://Scenes/GameBunnyAnims.tscn" id="2_alimv"]
[ext_resource type="Texture2D" uid="uid://daat37cyg0go5" path="res://Assets/Sprites/Start Menu Old/Easter Egg/Egg 3.png" id="3_1e3fe"]
[ext_resource type="PackedScene" uid="uid://cbfcolm6mjolp" path="res://Prefabs/Settings Menu.tscn" id="3_r3r61"]
[ext_resource type="Texture2D" uid="uid://dhvvw4yckl8x7" path="res://Assets/Sprites/Props/Cake.png" id="5_7ull8"]
[ext_resource type="Texture2D" uid="uid://c3yg6u8yncau3" path="res://Assets/Sprites/Easter Egg/Egg 2.png" id="6_45o7d"]
[ext_resource type="Texture2D" uid="uid://cp84ssaqs3pmp" path="res://Assets/Sprites/UI Elements/Jesus.png" id="6_wnx18"]
[ext_resource type="Texture2D" uid="uid://dkotcqflp3e32" path="res://Assets/Sprites/Easter Egg/Egg 1.png" id="7_285vd"]
[ext_resource type="Texture2D" uid="uid://dhvvw4yckl8x7" path="res://Assets/Sprites/Start Menu Old/Cake.png" id="5_7ull8"]
[ext_resource type="Texture2D" uid="uid://c3yg6u8yncau3" path="res://Assets/Sprites/Start Menu Old/Easter Egg/Egg 2.png" id="6_45o7d"]
[ext_resource type="Texture2D" uid="uid://cp84ssaqs3pmp" path="res://Assets/Sprites/Start Menu Old/Jesus.png" id="6_wnx18"]
[ext_resource type="Texture2D" uid="uid://dkotcqflp3e32" path="res://Assets/Sprites/Start Menu Old/Easter Egg/Egg 1.png" id="7_285vd"]
[ext_resource type="Theme" uid="uid://o3vg845para" path="res://Assets/UI_Theme.tres" id="8_lr748"]
[ext_resource type="Script" path="res://Scripts/UI/MenuButton.gd" id="9_2cu5l"]
[ext_resource type="Texture2D" uid="uid://6snf183fgfo5" path="res://Assets/Sprites/UI Elements/Cross.png" id="12_dhfc0"]
[ext_resource type="Texture2D" uid="uid://6snf183fgfo5" path="res://Assets/Sprites/Start Menu Old/Cross.png" id="12_dhfc0"]
[ext_resource type="AudioStream" uid="uid://c6nf5s6xy2uii" path="res://Assets/Temp Music/omw-to-beat-the-big-bad.wav" id="13_3j724"]
[node name="MainMenu" type="Node" node_paths=PackedStringArray("default_focus")]
script = ExtResource("1_qepq0")
game_scene = ExtResource("2_28004")
game_scene = ExtResource("2_alimv")
settings_scene = ExtResource("3_r3r61")
default_focus = NodePath("MainVBox/ButtonsVbox/PlayButton")

View file

@ -1,6 +1,7 @@
extends CharacterBody2D
class_name Bunny
@export var animation_player : AnimationPlayer
@export var min_distance_to_player := 80.0
@export var max_distance_to_player := 800.0
@export var agent : NavigationAgent2D
@ -33,6 +34,7 @@ func _physics_process(delta):
dir = self.global_position.direction_to(next_location).normalized()
if self.global_position.distance_to(player.global_position) > min_distance_to_player:
self.velocity = dir * delta * 60 * speed
update_animation()
if delta > 0.5:
print(delta)
move_and_slide()
@ -64,8 +66,19 @@ func sub_on_death(callback : Callable):
on_death_callbacks.push_front(callback)
pass
func update_animation():
var move_vector = Vector2(1 if velocity.x > 0 else (-1 if velocity.x < 0 else 0), 1 if velocity.y > 0 else (-1 if velocity.y < 0 else 0))
match move_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")
pass