mirror of
https://github.com/stevenhowes/GodotTest.git
synced 2026-05-27 04:01:01 +01:00
Basic walking (missing sprites)
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
extends CharacterBody2D
|
||||
|
||||
@export var move_speed : float = 100
|
||||
@export var starting_direction : Vector2 = Vector2(0,1)
|
||||
|
||||
@onready var animation_tree = $AnimationTree
|
||||
@onready var state_machine = animation_tree.get("parameters/playback")
|
||||
|
||||
func _ready():
|
||||
update_animation_parameters(starting_direction)
|
||||
|
||||
func _physics_process(_delta):
|
||||
var input_direction = Vector2(
|
||||
Input.get_action_strength("right") - Input.get_action_strength("left"),
|
||||
Input.get_action_strength("down") - Input.get_action_strength("up")
|
||||
)
|
||||
|
||||
update_animation_parameters(input_direction)
|
||||
|
||||
velocity = input_direction * move_speed
|
||||
|
||||
pick_new_state()
|
||||
|
||||
move_and_slide()
|
||||
|
||||
|
||||
|
||||
func update_animation_parameters(move_input: Vector2):
|
||||
if(move_input != Vector2.ZERO):
|
||||
animation_tree.set("parameters/Idle/blend_position", move_input)
|
||||
animation_tree.set("parameters/Walk/blend_position", move_input)
|
||||
|
||||
func pick_new_state():
|
||||
if(velocity != Vector2.ZERO):
|
||||
state_machine.travel("Walk")
|
||||
else:
|
||||
state_machine.travel("Idle")
|
||||
@@ -0,0 +1,262 @@
|
||||
[gd_scene load_steps=28 format=3 uid="uid://bn6l8gpt3e2cc"]
|
||||
|
||||
[ext_resource type="Script" path="res://Characters/player_boimler.gd" id="1_4xsm0"]
|
||||
[ext_resource type="Texture2D" uid="uid://c2ox6qx00um5f" path="res://Sprites/boimler.png" id="1_sm1i4"]
|
||||
|
||||
[sub_resource type="RectangleShape2D" id="RectangleShape2D_f68x6"]
|
||||
size = Vector2(15, 23)
|
||||
|
||||
[sub_resource type="Animation" id="Animation_we2gy"]
|
||||
resource_name = "walk_right"
|
||||
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": [16, 17, 18, 19, 20]
|
||||
}
|
||||
|
||||
[sub_resource type="Animation" id="Animation_cvcr0"]
|
||||
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": [16]
|
||||
}
|
||||
|
||||
[sub_resource type="Animation" id="Animation_gncbx"]
|
||||
resource_name = "idle_right"
|
||||
length = 3.0
|
||||
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, 2.9),
|
||||
"transitions": PackedFloat32Array(1, 1),
|
||||
"update": 1,
|
||||
"values": [14, 15]
|
||||
}
|
||||
|
||||
[sub_resource type="Animation" id="Animation_isqws"]
|
||||
resource_name = "idle_left"
|
||||
length = 3.0
|
||||
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, 2.9),
|
||||
"transitions": PackedFloat32Array(1, 1),
|
||||
"update": 1,
|
||||
"values": [21, 22]
|
||||
}
|
||||
|
||||
[sub_resource type="Animation" id="Animation_uh0nl"]
|
||||
resource_name = "walk_left"
|
||||
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": [23, 24, 25, 26, 27]
|
||||
}
|
||||
|
||||
[sub_resource type="Animation" id="Animation_aqig2"]
|
||||
resource_name = "walk_down"
|
||||
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": [9, 10, 11, 12, 13]
|
||||
}
|
||||
|
||||
[sub_resource type="Animation" id="Animation_odiyi"]
|
||||
resource_name = "walk_up"
|
||||
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": [9, 10, 11, 12, 13]
|
||||
}
|
||||
|
||||
[sub_resource type="Animation" id="Animation_shhac"]
|
||||
resource_name = "idle_down"
|
||||
length = 3.0
|
||||
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, 2.9),
|
||||
"transitions": PackedFloat32Array(1, 1),
|
||||
"update": 1,
|
||||
"values": [7, 8]
|
||||
}
|
||||
|
||||
[sub_resource type="Animation" id="Animation_vg36w"]
|
||||
resource_name = "idle_up"
|
||||
length = 3.0
|
||||
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, 2.9),
|
||||
"transitions": PackedFloat32Array(1, 1),
|
||||
"update": 1,
|
||||
"values": [0, 1]
|
||||
}
|
||||
|
||||
[sub_resource type="AnimationLibrary" id="AnimationLibrary_1a573"]
|
||||
_data = {
|
||||
"RESET": SubResource("Animation_cvcr0"),
|
||||
"idle_down": SubResource("Animation_shhac"),
|
||||
"idle_left": SubResource("Animation_isqws"),
|
||||
"idle_right": SubResource("Animation_gncbx"),
|
||||
"idle_up": SubResource("Animation_vg36w"),
|
||||
"walk_down": SubResource("Animation_aqig2"),
|
||||
"walk_left": SubResource("Animation_uh0nl"),
|
||||
"walk_right": SubResource("Animation_we2gy"),
|
||||
"walk_up": SubResource("Animation_odiyi")
|
||||
}
|
||||
|
||||
[sub_resource type="AnimationNodeAnimation" id="AnimationNodeAnimation_24qgq"]
|
||||
animation = &"idle_down"
|
||||
|
||||
[sub_resource type="AnimationNodeAnimation" id="AnimationNodeAnimation_yowcu"]
|
||||
animation = &"idle_up"
|
||||
|
||||
[sub_resource type="AnimationNodeAnimation" id="AnimationNodeAnimation_ngvgc"]
|
||||
animation = &"idle_left"
|
||||
|
||||
[sub_resource type="AnimationNodeAnimation" id="AnimationNodeAnimation_3fncq"]
|
||||
animation = &"idle_right"
|
||||
|
||||
[sub_resource type="AnimationNodeBlendSpace2D" id="AnimationNodeBlendSpace2D_nqkka"]
|
||||
blend_point_0/node = SubResource("AnimationNodeAnimation_24qgq")
|
||||
blend_point_0/pos = Vector2(0, 1.1)
|
||||
blend_point_1/node = SubResource("AnimationNodeAnimation_yowcu")
|
||||
blend_point_1/pos = Vector2(0, -1.1)
|
||||
blend_point_2/node = SubResource("AnimationNodeAnimation_ngvgc")
|
||||
blend_point_2/pos = Vector2(-1, 0)
|
||||
blend_point_3/node = SubResource("AnimationNodeAnimation_3fncq")
|
||||
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="AnimationNodeAnimation" id="AnimationNodeAnimation_cei2x"]
|
||||
animation = &"walk_down"
|
||||
|
||||
[sub_resource type="AnimationNodeAnimation" id="AnimationNodeAnimation_qo15p"]
|
||||
animation = &"walk_up"
|
||||
|
||||
[sub_resource type="AnimationNodeAnimation" id="AnimationNodeAnimation_dgdnw"]
|
||||
animation = &"walk_left"
|
||||
|
||||
[sub_resource type="AnimationNodeAnimation" id="AnimationNodeAnimation_nbcxn"]
|
||||
animation = &"walk_right"
|
||||
|
||||
[sub_resource type="AnimationNodeBlendSpace2D" id="AnimationNodeBlendSpace2D_idnn4"]
|
||||
blend_point_0/node = SubResource("AnimationNodeAnimation_cei2x")
|
||||
blend_point_0/pos = Vector2(0, 1.1)
|
||||
blend_point_1/node = SubResource("AnimationNodeAnimation_qo15p")
|
||||
blend_point_1/pos = Vector2(0, -1.1)
|
||||
blend_point_2/node = SubResource("AnimationNodeAnimation_dgdnw")
|
||||
blend_point_2/pos = Vector2(-1, 0)
|
||||
blend_point_3/node = SubResource("AnimationNodeAnimation_nbcxn")
|
||||
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="AnimationNodeStateMachineTransition_nxanf"]
|
||||
advance_mode = 0
|
||||
|
||||
[sub_resource type="AnimationNodeStateMachineTransition" id="AnimationNodeStateMachineTransition_acl43"]
|
||||
advance_mode = 0
|
||||
|
||||
[sub_resource type="AnimationNodeStateMachineTransition" id="AnimationNodeStateMachineTransition_xfad2"]
|
||||
advance_mode = 2
|
||||
|
||||
[sub_resource type="AnimationNodeStateMachine" id="AnimationNodeStateMachine_wgkrf"]
|
||||
states/Idle/node = SubResource("AnimationNodeBlendSpace2D_nqkka")
|
||||
states/Idle/position = Vector2(354, 100)
|
||||
states/Walk/node = SubResource("AnimationNodeBlendSpace2D_idnn4")
|
||||
states/Walk/position = Vector2(488, 100)
|
||||
transitions = ["Idle", "Walk", SubResource("AnimationNodeStateMachineTransition_nxanf"), "Walk", "Idle", SubResource("AnimationNodeStateMachineTransition_acl43"), "Start", "Idle", SubResource("AnimationNodeStateMachineTransition_xfad2")]
|
||||
|
||||
[node name="PlayerBoimler" type="CharacterBody2D"]
|
||||
script = ExtResource("1_4xsm0")
|
||||
|
||||
[node name="Sprite2D" type="Sprite2D" parent="."]
|
||||
texture = ExtResource("1_sm1i4")
|
||||
hframes = 7
|
||||
vframes = 4
|
||||
frame = 16
|
||||
|
||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
|
||||
position = Vector2(-0.5, 16.5)
|
||||
shape = SubResource("RectangleShape2D_f68x6")
|
||||
|
||||
[node name="AnimationPlayer" type="AnimationPlayer" parent="."]
|
||||
libraries = {
|
||||
"": SubResource("AnimationLibrary_1a573")
|
||||
}
|
||||
|
||||
[node name="AnimationTree" type="AnimationTree" parent="."]
|
||||
tree_root = SubResource("AnimationNodeStateMachine_wgkrf")
|
||||
anim_player = NodePath("../AnimationPlayer")
|
||||
active = true
|
||||
parameters/Idle/blend_position = Vector2(0, -1)
|
||||
parameters/Walk/blend_position = Vector2(0, 0)
|
||||
Reference in New Issue
Block a user