Skip to content

Commit 810761a

Browse files
author
Chris Bradfield
committed
KYN: YSort
1 parent bdb7654 commit 810761a

File tree

5 files changed

+120
-35
lines changed

5 files changed

+120
-35
lines changed

Know_Your_Nodes/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
“Know Your Nodes" is a series of Godot Game Engine videos where we take a single node type and show how it’s used. Maybe you’ve never come across this particular node before, or maybe you were just wondering what it’s for, but hopefully after this you’ll have a new tool you can use making your own games.

Know_Your_Nodes/ysort/main.tscn

Lines changed: 17 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -23,60 +23,56 @@ collision/mask = 1
2323
occluder/light_mask = 1
2424
tile_data = IntArray( 0, 0, 1, 0, 2, 0, 3, 0, 4, 0, 5, 0, 6, 0, 7, 0, 8, 0, 9, 0, 10, 0, 11, 0, 12, 0, 13, 0, 14, 0, 15, 0, 16, 0, 17, 0, 18, 0, 19, 0, 20, 0, 21, 0, 22, 0, 23, 0, 24, 0, 65536, 0, 65537, 1, 65538, 1, 65539, 1, 65540, 1, 65541, 1, 65542, 1, 65543, 1, 65544, 1, 65545, 1, 65546, 1, 65547, 1, 65548, 1, 65549, 1, 65550, 1, 65551, 1, 65552, 1, 65553, 1, 65554, 1, 65555, 1, 65556, 1, 65557, 1, 65558, 1, 65559, 1, 65560, 0, 131072, 0, 131073, 1, 131074, 1, 131075, 1, 131076, 1, 131077, 1, 131078, 1, 131079, 1, 131080, 1, 131081, 1, 131082, 1, 131083, 1, 131084, 1, 131085, 1, 131086, 1, 131087, 1, 131088, 1, 131089, 1, 131090, 1, 131091, 1, 131092, 1, 131093, 1, 131094, 1, 131095, 1, 131096, 0, 196608, 0, 196609, 1, 196610, 1, 196611, 1, 196612, 1, 196613, 1, 196614, 1, 196615, 1, 196616, 1, 196617, 1, 196618, 1, 196619, 1, 196620, 1, 196621, 1, 196622, 1, 196623, 1, 196624, 1, 196625, 1, 196626, 1, 196627, 1, 196628, 1, 196629, 1, 196630, 1, 196631, 1, 196632, 0, 262144, 0, 262145, 1, 262146, 1, 262147, 1, 262148, 1, 262149, 1, 262150, 1, 262151, 1, 262152, 1, 262153, 1, 262154, 1, 262155, 1, 262156, 1, 262157, 1, 262158, 1, 262159, 1, 262160, 1, 262161, 1, 262162, 1, 262163, 1, 262164, 1, 262165, 1, 262166, 1, 262167, 1, 262168, 0, 327680, 0, 327681, 1, 327682, 1, 327683, 1, 327684, 1, 327685, 1, 327686, 1, 327687, 1, 327688, 1, 327689, 1, 327690, 1, 327691, 1, 327692, 1, 327693, 1, 327694, 1, 327695, 1, 327696, 1, 327697, 1, 327698, 1, 327699, 1, 327700, 1, 327701, 1, 327702, 1, 327703, 1, 327704, 0, 393216, 0, 393217, 1, 393218, 1, 393219, 1, 393220, 1, 393221, 1, 393222, 0, 393223, 1, 393224, 1, 393225, 1, 393226, 1, 393227, 1, 393228, 1, 393229, 1, 393230, 1, 393231, 1, 393232, 1, 393233, 0, 393234, 1, 393235, 1, 393236, 1, 393237, 1, 393238, 1, 393239, 1, 393240, 0, 458752, 0, 458753, 1, 458754, 1, 458755, 1, 458756, 1, 458757, 1, 458758, 0, 458759, 1, 458760, 1, 458761, 1, 458762, 1, 458763, 1, 458764, 1, 458765, 1, 458766, 1, 458767, 1, 458768, 1, 458769, 0, 458770, 1, 458771, 1, 458772, 1, 458773, 1, 458774, 1, 458775, 1, 458776, 0, 524288, 0, 524289, 1, 524290, 1, 524291, 1, 524292, 1, 524293, 1, 524294, 0, 524295, 1, 524296, 1, 524297, 1, 524298, 1, 524299, 1, 524300, 1, 524301, 1, 524302, 1, 524303, 1, 524304, 1, 524305, 0, 524306, 1, 524307, 1, 524308, 1, 524309, 1, 524310, 1, 524311, 1, 524312, 0, 589824, 0, 589825, 1, 589826, 1, 589827, 1, 589828, 1, 589829, 1, 589830, 0, 589831, 1, 589832, 1, 589833, 1, 589834, 1, 589835, 1, 589836, 1, 589837, 1, 589838, 1, 589839, 1, 589840, 1, 589841, 0, 589842, 1, 589843, 1, 589844, 1, 589845, 1, 589846, 1, 589847, 1, 589848, 0, 655360, 0, 655361, 1, 655362, 1, 655363, 1, 655364, 1, 655365, 1, 655366, 0, 655367, 1, 655368, 1, 655369, 1, 655370, 1, 655371, 1, 655372, 1, 655373, 1, 655374, 1, 655375, 1, 655376, 1, 655377, 0, 655378, 1, 655379, 1, 655380, 1, 655381, 1, 655382, 1, 655383, 1, 655384, 0, 720896, 0, 720897, 1, 720898, 1, 720899, 1, 720900, 1, 720901, 1, 720902, 0, 720903, 1, 720904, 1, 720905, 1, 720906, 1, 720907, 1, 720908, 1, 720909, 1, 720910, 1, 720911, 1, 720912, 1, 720913, 0, 720914, 1, 720915, 1, 720916, 1, 720917, 1, 720918, 1, 720919, 1, 720920, 0, 786432, 0, 786433, 1, 786434, 1, 786435, 1, 786436, 1, 786437, 1, 786438, 0, 786439, 1, 786440, 1, 786441, 1, 786442, 1, 786443, 1, 786444, 1, 786445, 1, 786446, 1, 786447, 1, 786448, 1, 786449, 0, 786450, 1, 786451, 1, 786452, 1, 786453, 1, 786454, 1, 786455, 1, 786456, 0, 851968, 0, 851969, 1, 851970, 1, 851971, 1, 851972, 1, 851973, 1, 851974, 1, 851975, 1, 851976, 1, 851977, 1, 851978, 1, 851979, 1, 851980, 1, 851981, 1, 851982, 1, 851983, 1, 851984, 1, 851985, 1, 851986, 1, 851987, 1, 851988, 1, 851989, 1, 851990, 1, 851991, 1, 851992, 0, 917504, 0, 917505, 1, 917506, 1, 917507, 1, 917508, 1, 917509, 1, 917510, 1, 917511, 1, 917512, 1, 917513, 1, 917514, 1, 917515, 1, 917516, 1, 917517, 1, 917518, 1, 917519, 1, 917520, 1, 917521, 1, 917522, 1, 917523, 1, 917524, 1, 917525, 1, 917526, 1, 917527, 1, 917528, 0, 983040, 0, 983041, 1, 983042, 1, 983043, 1, 983044, 1, 983045, 1, 983046, 1, 983047, 1, 983048, 1, 983049, 1, 983050, 1, 983051, 1, 983052, 1, 983053, 1, 983054, 1, 983055, 1, 983056, 1, 983057, 1, 983058, 1, 983059, 1, 983060, 1, 983061, 1, 983062, 1, 983063, 1, 983064, 0, 1048576, 0, 1048577, 1, 1048578, 1, 1048579, 1, 1048580, 1, 1048581, 1, 1048582, 1, 1048583, 1, 1048584, 1, 1048585, 1, 1048586, 1, 1048587, 1, 1048588, 1, 1048589, 1, 1048590, 1, 1048591, 1, 1048592, 1, 1048593, 1, 1048594, 1, 1048595, 1, 1048596, 1, 1048597, 1, 1048598, 1, 1048599, 1, 1048600, 0, 1114112, 0, 1114113, 1, 1114114, 1, 1114115, 1, 1114116, 1, 1114117, 1, 1114118, 1, 1114119, 1, 1114120, 1, 1114121, 1, 1114122, 1, 1114123, 1, 1114124, 1, 1114125, 1, 1114126, 1, 1114127, 1, 1114128, 1, 1114129, 1, 1114130, 1, 1114131, 1, 1114132, 1, 1114133, 1, 1114134, 1, 1114135, 1, 1114136, 0, 1179648, 0, 1179649, 0, 1179650, 0, 1179651, 0, 1179652, 0, 1179653, 0, 1179654, 0, 1179655, 0, 1179656, 0, 1179657, 0, 1179658, 0, 1179659, 0, 1179660, 0, 1179661, 0, 1179662, 0, 1179663, 0, 1179664, 0, 1179665, 0, 1179666, 0, 1179667, 0, 1179668, 0, 1179669, 0, 1179670, 0, 1179671, 0, 1179672, 0 )
2525

26-
[node name="YSort" type="YSort" parent="."]
27-
28-
sort/enabled = true
29-
30-
[node name="npc" parent="YSort" instance=ExtResource( 2 )]
26+
[node name="npc" parent="." instance=ExtResource( 2 )]
3127

3228
transform/pos = Vector2( 380.195, 179.664 )
3329

34-
[node name="npc 1" parent="YSort" instance=ExtResource( 2 )]
30+
[node name="npc 1" parent="." instance=ExtResource( 2 )]
3531

36-
transform/pos = Vector2( 101.634, 274.147 )
32+
transform/pos = Vector2( 497.2, 121.239 )
3733

38-
[node name="npc 2" parent="YSort" instance=ExtResource( 2 )]
34+
[node name="npc 2" parent="." instance=ExtResource( 2 )]
3935

4036
transform/pos = Vector2( 663.644, 383.29 )
4137

42-
[node name="npc 3" parent="YSort" instance=ExtResource( 2 )]
38+
[node name="npc 3" parent="." instance=ExtResource( 2 )]
4339

4440
transform/pos = Vector2( 208.335, 127.536 )
4541

46-
[node name="npc 4" parent="YSort" instance=ExtResource( 2 )]
42+
[node name="npc 4" parent="." instance=ExtResource( 2 )]
4743

48-
transform/pos = Vector2( 626.176, 137.31 )
44+
transform/pos = Vector2( 647.229, 150.606 )
4945

50-
[node name="npc 5" parent="YSort" instance=ExtResource( 2 )]
46+
[node name="npc 5" parent="." instance=ExtResource( 2 )]
5147

5248
transform/pos = Vector2( 400.558, 393.065 )
5349

54-
[node name="npc 6" parent="YSort" instance=ExtResource( 2 )]
50+
[node name="npc 6" parent="." instance=ExtResource( 2 )]
5551

5652
transform/pos = Vector2( 180.641, 497.321 )
5753

58-
[node name="npc 7" parent="YSort" instance=ExtResource( 2 )]
54+
[node name="npc 7" parent="." instance=ExtResource( 2 )]
5955

6056
transform/pos = Vector2( 321.551, 289.622 )
6157

62-
[node name="npc 8" parent="YSort" instance=ExtResource( 2 )]
58+
[node name="npc 8" parent="." instance=ExtResource( 2 )]
6359

6460
transform/pos = Vector2( 439.654, 287.179 )
6561

66-
[node name="npc 9" parent="YSort" instance=ExtResource( 2 )]
62+
[node name="npc 9" parent="." instance=ExtResource( 2 )]
6763

6864
transform/pos = Vector2( 355.76, 419.943 )
6965

70-
[node name="npc 10" parent="YSort" instance=ExtResource( 2 )]
66+
[node name="npc 10" parent="." instance=ExtResource( 2 )]
7167

7268
transform/pos = Vector2( 528.436, 500.579 )
7369

74-
[node name="npc 11" parent="YSort" instance=ExtResource( 2 )]
70+
[node name="npc 11" parent="." instance=ExtResource( 2 )]
7571

76-
transform/pos = Vector2( 498.299, 126.721 )
72+
transform/pos = Vector2( 109.381, 214.255 )
7773

78-
[node name="npc 12" parent="YSort" instance=ExtResource( 2 )]
74+
[node name="npc 12" parent="." instance=ExtResource( 2 )]
7975

80-
transform/pos = Vector2( 108.966, 121.834 )
76+
transform/pos = Vector2( 110.074, 178.343 )
8177

8278

Know_Your_Nodes/ysort/main2.tscn

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
[gd_scene load_steps=3 format=1]
2+
3+
[ext_resource path="res://tiles.tres" type="TileSet" id=1]
4+
[ext_resource path="res://npc.tscn" type="PackedScene" id=2]
5+
6+
[node name="main" type="Node"]
7+
8+
[node name="TileMap" type="TileMap" parent="."]
9+
10+
mode = 0
11+
tile_set = ExtResource( 1 )
12+
cell/size = Vector2( 32, 32 )
13+
cell/quadrant_size = 16
14+
cell/custom_transform = Matrix32( 1, 0, 0, 1, 0, 0 )
15+
cell/half_offset = 2
16+
cell/tile_origin = 0
17+
cell/y_sort = false
18+
collision/use_kinematic = false
19+
collision/friction = 1.0
20+
collision/bounce = 0.0
21+
collision/layers = 1
22+
collision/mask = 1
23+
occluder/light_mask = 1
24+
tile_data = IntArray( 0, 0, 1, 0, 2, 0, 3, 0, 4, 0, 5, 0, 6, 0, 7, 0, 8, 0, 9, 0, 10, 0, 11, 0, 12, 0, 13, 0, 14, 0, 15, 0, 16, 0, 17, 0, 18, 0, 19, 0, 20, 0, 21, 0, 22, 0, 23, 0, 24, 0, 65536, 0, 65537, 1, 65538, 1, 65539, 1, 65540, 1, 65541, 1, 65542, 1, 65543, 1, 65544, 1, 65545, 1, 65546, 1, 65547, 1, 65548, 1, 65549, 1, 65550, 1, 65551, 1, 65552, 1, 65553, 1, 65554, 1, 65555, 1, 65556, 1, 65557, 1, 65558, 1, 65559, 1, 65560, 0, 131072, 0, 131073, 1, 131074, 1, 131075, 1, 131076, 1, 131077, 1, 131078, 1, 131079, 1, 131080, 1, 131081, 1, 131082, 1, 131083, 1, 131084, 1, 131085, 1, 131086, 1, 131087, 1, 131088, 1, 131089, 1, 131090, 1, 131091, 1, 131092, 1, 131093, 1, 131094, 1, 131095, 1, 131096, 0, 196608, 0, 196609, 1, 196610, 1, 196611, 1, 196612, 1, 196613, 1, 196614, 1, 196615, 1, 196616, 1, 196617, 1, 196618, 1, 196619, 1, 196620, 1, 196621, 1, 196622, 1, 196623, 1, 196624, 1, 196625, 1, 196626, 1, 196627, 1, 196628, 1, 196629, 1, 196630, 1, 196631, 1, 196632, 0, 262144, 0, 262145, 1, 262146, 1, 262147, 1, 262148, 1, 262149, 1, 262150, 1, 262151, 1, 262152, 1, 262153, 1, 262154, 1, 262155, 1, 262156, 1, 262157, 1, 262158, 1, 262159, 1, 262160, 1, 262161, 1, 262162, 1, 262163, 1, 262164, 1, 262165, 1, 262166, 1, 262167, 1, 262168, 0, 327680, 0, 327681, 1, 327682, 1, 327683, 1, 327684, 1, 327685, 1, 327686, 1, 327687, 1, 327688, 1, 327689, 1, 327690, 1, 327691, 1, 327692, 1, 327693, 1, 327694, 1, 327695, 1, 327696, 1, 327697, 1, 327698, 1, 327699, 1, 327700, 1, 327701, 1, 327702, 1, 327703, 1, 327704, 0, 393216, 0, 393217, 1, 393218, 1, 393219, 1, 393220, 1, 393221, 1, 393222, 0, 393223, 1, 393224, 1, 393225, 1, 393226, 1, 393227, 1, 393228, 1, 393229, 1, 393230, 1, 393231, 1, 393232, 1, 393233, 0, 393234, 1, 393235, 1, 393236, 1, 393237, 1, 393238, 1, 393239, 1, 393240, 0, 458752, 0, 458753, 1, 458754, 1, 458755, 1, 458756, 1, 458757, 1, 458758, 0, 458759, 1, 458760, 1, 458761, 1, 458762, 1, 458763, 1, 458764, 1, 458765, 1, 458766, 1, 458767, 1, 458768, 1, 458769, 0, 458770, 1, 458771, 1, 458772, 1, 458773, 1, 458774, 1, 458775, 1, 458776, 0, 524288, 0, 524289, 1, 524290, 1, 524291, 1, 524292, 1, 524293, 1, 524294, 0, 524295, 1, 524296, 1, 524297, 1, 524298, 1, 524299, 1, 524300, 1, 524301, 1, 524302, 1, 524303, 1, 524304, 1, 524305, 0, 524306, 1, 524307, 1, 524308, 1, 524309, 1, 524310, 1, 524311, 1, 524312, 0, 589824, 0, 589825, 1, 589826, 1, 589827, 1, 589828, 1, 589829, 1, 589830, 0, 589831, 1, 589832, 1, 589833, 1, 589834, 1, 589835, 1, 589836, 1, 589837, 1, 589838, 1, 589839, 1, 589840, 1, 589841, 0, 589842, 1, 589843, 1, 589844, 1, 589845, 1, 589846, 1, 589847, 1, 589848, 0, 655360, 0, 655361, 1, 655362, 1, 655363, 1, 655364, 1, 655365, 1, 655366, 0, 655367, 1, 655368, 1, 655369, 1, 655370, 1, 655371, 1, 655372, 1, 655373, 1, 655374, 1, 655375, 1, 655376, 1, 655377, 0, 655378, 1, 655379, 1, 655380, 1, 655381, 1, 655382, 1, 655383, 1, 655384, 0, 720896, 0, 720897, 1, 720898, 1, 720899, 1, 720900, 1, 720901, 1, 720902, 0, 720903, 1, 720904, 1, 720905, 1, 720906, 1, 720907, 1, 720908, 1, 720909, 1, 720910, 1, 720911, 1, 720912, 1, 720913, 0, 720914, 1, 720915, 1, 720916, 1, 720917, 1, 720918, 1, 720919, 1, 720920, 0, 786432, 0, 786433, 1, 786434, 1, 786435, 1, 786436, 1, 786437, 1, 786438, 0, 786439, 1, 786440, 1, 786441, 1, 786442, 1, 786443, 1, 786444, 1, 786445, 1, 786446, 1, 786447, 1, 786448, 1, 786449, 0, 786450, 1, 786451, 1, 786452, 1, 786453, 1, 786454, 1, 786455, 1, 786456, 0, 851968, 0, 851969, 1, 851970, 1, 851971, 1, 851972, 1, 851973, 1, 851974, 1, 851975, 1, 851976, 1, 851977, 1, 851978, 1, 851979, 1, 851980, 1, 851981, 1, 851982, 1, 851983, 1, 851984, 1, 851985, 1, 851986, 1, 851987, 1, 851988, 1, 851989, 1, 851990, 1, 851991, 1, 851992, 0, 917504, 0, 917505, 1, 917506, 1, 917507, 1, 917508, 1, 917509, 1, 917510, 1, 917511, 1, 917512, 1, 917513, 1, 917514, 1, 917515, 1, 917516, 1, 917517, 1, 917518, 1, 917519, 1, 917520, 1, 917521, 1, 917522, 1, 917523, 1, 917524, 1, 917525, 1, 917526, 1, 917527, 1, 917528, 0, 983040, 0, 983041, 1, 983042, 1, 983043, 1, 983044, 1, 983045, 1, 983046, 1, 983047, 1, 983048, 1, 983049, 1, 983050, 1, 983051, 1, 983052, 1, 983053, 1, 983054, 1, 983055, 1, 983056, 1, 983057, 1, 983058, 1, 983059, 1, 983060, 1, 983061, 1, 983062, 1, 983063, 1, 983064, 0, 1048576, 0, 1048577, 1, 1048578, 1, 1048579, 1, 1048580, 1, 1048581, 1, 1048582, 1, 1048583, 1, 1048584, 1, 1048585, 1, 1048586, 1, 1048587, 1, 1048588, 1, 1048589, 1, 1048590, 1, 1048591, 1, 1048592, 1, 1048593, 1, 1048594, 1, 1048595, 1, 1048596, 1, 1048597, 1, 1048598, 1, 1048599, 1, 1048600, 0, 1114112, 0, 1114113, 1, 1114114, 1, 1114115, 1, 1114116, 1, 1114117, 1, 1114118, 1, 1114119, 1, 1114120, 1, 1114121, 1, 1114122, 1, 1114123, 1, 1114124, 1, 1114125, 1, 1114126, 1, 1114127, 1, 1114128, 1, 1114129, 1, 1114130, 1, 1114131, 1, 1114132, 1, 1114133, 1, 1114134, 1, 1114135, 1, 1114136, 0, 1179648, 0, 1179649, 0, 1179650, 0, 1179651, 0, 1179652, 0, 1179653, 0, 1179654, 0, 1179655, 0, 1179656, 0, 1179657, 0, 1179658, 0, 1179659, 0, 1179660, 0, 1179661, 0, 1179662, 0, 1179663, 0, 1179664, 0, 1179665, 0, 1179666, 0, 1179667, 0, 1179668, 0, 1179669, 0, 1179670, 0, 1179671, 0, 1179672, 0 )
25+
26+
[node name="YSort" type="YSort" parent="."]
27+
28+
sort/enabled = true
29+
30+
[node name="npc" parent="YSort" instance=ExtResource( 2 )]
31+
32+
transform/pos = Vector2( 380.195, 179.664 )
33+
34+
[node name="npc 1" parent="YSort" instance=ExtResource( 2 )]
35+
36+
transform/pos = Vector2( 101.634, 274.147 )
37+
38+
[node name="npc 2" parent="YSort" instance=ExtResource( 2 )]
39+
40+
transform/pos = Vector2( 663.644, 383.29 )
41+
42+
[node name="npc 3" parent="YSort" instance=ExtResource( 2 )]
43+
44+
transform/pos = Vector2( 208.335, 127.536 )
45+
46+
[node name="npc 4" parent="YSort" instance=ExtResource( 2 )]
47+
48+
transform/pos = Vector2( 626.176, 137.31 )
49+
50+
[node name="npc 5" parent="YSort" instance=ExtResource( 2 )]
51+
52+
transform/pos = Vector2( 400.558, 393.065 )
53+
54+
[node name="npc 6" parent="YSort" instance=ExtResource( 2 )]
55+
56+
transform/pos = Vector2( 180.641, 497.321 )
57+
58+
[node name="npc 7" parent="YSort" instance=ExtResource( 2 )]
59+
60+
transform/pos = Vector2( 321.551, 289.622 )
61+
62+
[node name="npc 8" parent="YSort" instance=ExtResource( 2 )]
63+
64+
transform/pos = Vector2( 439.654, 287.179 )
65+
66+
[node name="npc 9" parent="YSort" instance=ExtResource( 2 )]
67+
68+
transform/pos = Vector2( 355.76, 419.943 )
69+
70+
[node name="npc 10" parent="YSort" instance=ExtResource( 2 )]
71+
72+
transform/pos = Vector2( 528.436, 500.579 )
73+
74+
[node name="npc 11" parent="YSort" instance=ExtResource( 2 )]
75+
76+
transform/pos = Vector2( 498.299, 126.721 )
77+
78+
[node name="npc 12" parent="YSort" instance=ExtResource( 2 )]
79+
80+
transform/pos = Vector2( 108.966, 121.834 )
81+
82+

Know_Your_Nodes/ysort/npc.gd

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
extends KinematicBody2D
22

3+
export(bool) var moving = true
4+
35
onready var sprite = get_node("sprite")
46
onready var anim = get_node("animation")
57

@@ -30,17 +32,20 @@ func _ready():
3032
set_fixed_process(true)
3133

3234
func _fixed_process(delta):
33-
var motion = move(dir * speed * delta)
34-
if is_colliding():
35-
var n = get_collision_normal()
36-
move(n.slide(motion))
37-
dir = n
38-
if n.x > 0:
39-
facing = 'r'
40-
if n.x < 0:
41-
facing = 'l'
42-
if n.y > 0:
43-
facing = 'd'
44-
if n.y < 0:
45-
facing = 'u'
46-
anim.play(facing)
35+
if not moving:
36+
anim.stop()
37+
if moving:
38+
var motion = move(dir * speed * delta)
39+
if is_colliding():
40+
var n = get_collision_normal()
41+
move(n.slide(motion))
42+
dir = n
43+
if n.x > 0:
44+
facing = 'r'
45+
if n.x < 0:
46+
facing = 'l'
47+
if n.y > 0:
48+
facing = 'd'
49+
if n.y < 0:
50+
facing = 'u'
51+
anim.play(facing)

Know_Your_Nodes/ysort/npc.tscn

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ script/script = ExtResource( 1 )
8989
__meta__ = {
9090
"_edit_group_": true
9191
}
92+
moving = true
9293

9394
[node name="animation" type="AnimationPlayer" parent="."]
9495

0 commit comments

Comments
 (0)