roll animation
parent
e586ae0e6d
commit
19b8bf362d
|
@ -1,4 +1,4 @@
|
|||
[gd_scene load_steps=30 format=3 uid="uid://b2254pup8k161"]
|
||||
[gd_scene load_steps=33 format=3 uid="uid://b2254pup8k161"]
|
||||
|
||||
[ext_resource type="Script" path="res://Characters/Player.cs" id="1_flygr"]
|
||||
[ext_resource type="Shader" path="res://Shaders/Flash.gdshader" id="2_ngsgt"]
|
||||
|
@ -134,6 +134,44 @@ _data = {
|
|||
"RESET": SubResource("Animation_k6l16")
|
||||
}
|
||||
|
||||
[sub_resource type="Animation" id="Animation_rx2pj"]
|
||||
resource_name = "roll"
|
||||
length = 0.5
|
||||
step = 0.05
|
||||
tracks/0/type = "value"
|
||||
tracks/0/imported = false
|
||||
tracks/0/enabled = true
|
||||
tracks/0/path = NodePath("Sprite:rotation")
|
||||
tracks/0/interp = 1
|
||||
tracks/0/loop_wrap = true
|
||||
tracks/0/keys = {
|
||||
"times": PackedFloat32Array(0, 0.25, 0.5),
|
||||
"transitions": PackedFloat32Array(1, 1, 1),
|
||||
"update": 0,
|
||||
"values": [0.0, 3.14159, 6.28319]
|
||||
}
|
||||
|
||||
[sub_resource type="Animation" id="Animation_yejx2"]
|
||||
length = 0.001
|
||||
tracks/0/type = "value"
|
||||
tracks/0/imported = false
|
||||
tracks/0/enabled = true
|
||||
tracks/0/path = NodePath("Sprite:rotation")
|
||||
tracks/0/interp = 1
|
||||
tracks/0/loop_wrap = true
|
||||
tracks/0/keys = {
|
||||
"times": PackedFloat32Array(0),
|
||||
"transitions": PackedFloat32Array(1),
|
||||
"update": 0,
|
||||
"values": [0.0]
|
||||
}
|
||||
|
||||
[sub_resource type="AnimationLibrary" id="AnimationLibrary_jai06"]
|
||||
_data = {
|
||||
"RESET": SubResource("Animation_yejx2"),
|
||||
"roll": SubResource("Animation_rx2pj")
|
||||
}
|
||||
|
||||
[node name="Player" type="CharacterBody2D" node_paths=PackedStringArray("Camera", "DirectionMarker", "Sprite", "Inventory", "StateMachine", "Hurtbox")]
|
||||
y_sort_enabled = true
|
||||
texture_filter = 3
|
||||
|
@ -178,8 +216,10 @@ position_smoothing_speed = 8.0
|
|||
|
||||
[node name="Sprite" type="AnimatedSprite2D" parent="."]
|
||||
use_parent_material = true
|
||||
position = Vector2(0, 4)
|
||||
sprite_frames = SubResource("SpriteFrames_2h7cf")
|
||||
animation = &"idle"
|
||||
offset = Vector2(0, -4)
|
||||
|
||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
|
||||
position = Vector2(0, 8)
|
||||
|
@ -202,10 +242,11 @@ horizontal_alignment = 1
|
|||
|
||||
[node name="Node" type="Node" parent="."]
|
||||
|
||||
[node name="Inventory" type="Node2D" parent="."]
|
||||
[node name="Inventory" type="Node2D" parent="." node_paths=PackedStringArray("Items")]
|
||||
y_sort_enabled = true
|
||||
position = Vector2(0, 4)
|
||||
script = ExtResource("7_xyenu")
|
||||
Items = []
|
||||
InventoryMap = {
|
||||
"equip_1": 0,
|
||||
"equip_2": 1
|
||||
|
@ -227,6 +268,11 @@ libraries = {
|
|||
"": SubResource("AnimationLibrary_xe5eq")
|
||||
}
|
||||
|
||||
[node name="RollAnimation" type="AnimationPlayer" parent="."]
|
||||
libraries = {
|
||||
"": SubResource("AnimationLibrary_jai06")
|
||||
}
|
||||
|
||||
[node name="HurtSound" type="AudioStreamPlayer2D" parent="."]
|
||||
stream = ExtResource("12_h0x0g")
|
||||
max_distance = 64.0
|
||||
|
|
|
@ -8,12 +8,28 @@ public partial class PlayerRollState : PlayerState
|
|||
|
||||
private Vector2 _rollDirection = Vector2.Zero;
|
||||
|
||||
private AnimationPlayer _rollAnimation;
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
_rollAnimation = _player.GetNode<AnimationPlayer>("RollAnimation");
|
||||
base._Ready();
|
||||
}
|
||||
|
||||
public override IState<CharacterState> Enter(IState<CharacterState> previousState)
|
||||
{
|
||||
_timeLeftToRoll = 0.5;
|
||||
// roll the direction we were previously moving in
|
||||
_rollDirection = Character.Direction;
|
||||
Character.Target = Character.Direction;
|
||||
if (Character.Direction.X >= 0)
|
||||
{
|
||||
_rollAnimation.Play("roll");
|
||||
}
|
||||
else
|
||||
{
|
||||
_rollAnimation.PlayBackwards("roll");
|
||||
}
|
||||
return base.Enter(previousState);
|
||||
}
|
||||
|
||||
|
@ -23,6 +39,7 @@ public partial class PlayerRollState : PlayerState
|
|||
// this state (e.g. from death)
|
||||
_timeLeftToRoll = 0;
|
||||
_rollDirection = Character.Direction;
|
||||
_rollAnimation.Stop();
|
||||
base.Exit(nextState);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue