animationtree

This commit is contained in:
mightypanders 2021-04-03 23:51:22 +02:00
parent 6a995b45ea
commit df30f1f8ef
2 changed files with 86 additions and 10 deletions

View File

@ -6,6 +6,8 @@ const ACCELERATION = 500
const FRICTION = 500
onready var animationPlayer = $AnimationPlayer
onready var animationTree = $AnimationTree
onready var animationState = animationTree.get('parameters/playback')
func _physics_process(delta):
@ -14,15 +16,12 @@ func _physics_process(delta):
input_vector.y = Input.get_action_strength("ui_down") - Input.get_action_strength("ui_up")
input_vector = input_vector.normalized()
if input_vector != Vector2.ZERO:
if input_vector.x > 0:
animationPlayer.play("Walk_Right")
if input_vector.x < 0:
animationPlayer.play("Walk_Left")
animationTree.set("parameters/Walk/blend_position",input_vector)
animationTree.set("parameters/Idle/blend_position",input_vector)
animationState.travel("Walk")
velocity = velocity.move_toward(input_vector*MAX_SPEED,ACCELERATION*delta)
else:
animationPlayer.play("Idle_Right")
animationState.travel("Idle")
velocity = velocity.move_toward(Vector2.ZERO, FRICTION*delta)
velocity = move_and_slide(velocity)

View File

@ -1,4 +1,4 @@
[gd_scene load_steps=12 format=2]
[gd_scene load_steps=28 format=2]
[ext_resource path="res://assets/Player/Player.png" type="Texture" id=1]
[ext_resource path="res://script/player/Player.gd" type="Script" id=2]
@ -142,6 +142,76 @@ tracks/0/keys = {
"values": [ 7, 8, 9, 10, 11, 6 ]
}
[sub_resource type="AnimationNodeAnimation" id=10]
animation = "Idle_down"
[sub_resource type="AnimationNodeAnimation" id=11]
animation = "Idle_Right"
[sub_resource type="AnimationNodeAnimation" id=12]
animation = "Idle_Up"
[sub_resource type="AnimationNodeAnimation" id=13]
animation = "Idle_Left"
[sub_resource type="AnimationNodeStateMachine" id=14]
[sub_resource type="AnimationNodeBlendSpace2D" id=15]
blend_point_0/node = SubResource( 10 )
blend_point_0/pos = Vector2( 0, 1.1 )
blend_point_1/node = SubResource( 11 )
blend_point_1/pos = Vector2( 1, 0 )
blend_point_2/node = SubResource( 12 )
blend_point_2/pos = Vector2( 0, -1.1 )
blend_point_3/node = SubResource( 13 )
blend_point_3/pos = Vector2( -1, 0 )
blend_point_4/node = SubResource( 14 )
blend_point_4/pos = Vector2( 0, -1.1 )
min_space = Vector2( -1, -1.1 )
max_space = Vector2( 1, 1.1 )
blend_mode = 1
[sub_resource type="AnimationNodeAnimation" id=19]
animation = "Walk_Down"
[sub_resource type="AnimationNodeAnimation" id=20]
animation = "Walk_Right"
[sub_resource type="AnimationNodeAnimation" id=21]
animation = "Walk_Up"
[sub_resource type="AnimationNodeAnimation" id=22]
animation = "Walk_Left"
[sub_resource type="AnimationNodeBlendSpace2D" id=23]
blend_point_0/node = SubResource( 19 )
blend_point_0/pos = Vector2( 0, 1.1 )
blend_point_1/node = SubResource( 20 )
blend_point_1/pos = Vector2( 1, 0 )
blend_point_2/node = SubResource( 21 )
blend_point_2/pos = Vector2( 0, -1.1 )
blend_point_3/node = SubResource( 22 )
blend_point_3/pos = Vector2( -1, 0 )
min_space = Vector2( -1, -1.1 )
max_space = Vector2( 1, 1.1 )
blend_mode = 1
[sub_resource type="AnimationNodeStateMachineTransition" id=24]
[sub_resource type="AnimationNodeStateMachineTransition" id=25]
[sub_resource type="AnimationNodeStateMachine" id=16]
states/Idle/node = SubResource( 15 )
states/Idle/position = Vector2( 629, 126 )
states/Walk/node = SubResource( 23 )
states/Walk/position = Vector2( 807, 126 )
transitions = [ "Idle", "Walk", SubResource( 24 ), "Walk", "Idle", SubResource( 25 ) ]
start_node = "Idle"
[sub_resource type="AnimationNodeStateMachinePlayback" id=17]
[sub_resource type="AnimationNodeStateMachinePlayback" id=18]
[node name="Player" type="KinematicBody2D"]
z_index = 1
script = ExtResource( 2 )
@ -150,7 +220,6 @@ script = ExtResource( 2 )
position = Vector2( 0, -8.04334 )
texture = ExtResource( 1 )
hframes = 60
frame = 19
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
position = Vector2( -1.41422, 0.440334 )
@ -161,7 +230,6 @@ __meta__ = {
}
[node name="AnimationPlayer" type="AnimationPlayer" parent="."]
autoplay = "Walk_Down"
anims/Idle_Left = SubResource( 8 )
anims/Idle_Right = SubResource( 2 )
anims/Idle_Up = SubResource( 3 )
@ -170,3 +238,12 @@ anims/Walk_Down = SubResource( 4 )
anims/Walk_Left = SubResource( 5 )
anims/Walk_Right = SubResource( 6 )
anims/Walk_Up = SubResource( 7 )
[node name="AnimationTree" type="AnimationTree" parent="."]
tree_root = SubResource( 16 )
anim_player = NodePath("../AnimationPlayer")
active = true
parameters/playback = SubResource( 17 )
parameters/Idle/blend_position = Vector2( 0, 0 )
parameters/Idle/4/playback = SubResource( 18 )
parameters/Walk/blend_position = Vector2( 0, 0 )