Skip to content

Commit 666f35a

Browse files
authored
Actor movement simplified through Pivot removal. (gdquest-demos#64)
* Removed the use of a pivot. This small change eliminates the use of a Pivot (Position2D) to move the character. The position is updated after the animation ends, which makes no difference since the update has already been done in the Grid. * Updated Actor.tscn according to change in script. This change reflects the changes in ./actor.gd * Removed all instances of Pivot. * Removed comments.
1 parent 167c1ac commit 666f35a

File tree

2 files changed

+12
-12
lines changed

2 files changed

+12
-12
lines changed

2018/06-09-grid-based-movement/pawns/Actor.tscn

+5-9
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ length = 0.1
1010
loop = false
1111
step = 0.01
1212
tracks/0/type = "value"
13-
tracks/0/path = NodePath("Pivot/Sprite:position")
13+
tracks/0/path = NodePath("Sprite:position")
1414
tracks/0/interp = 1
1515
tracks/0/loop_wrap = true
1616
tracks/0/imported = false
@@ -29,7 +29,7 @@ length = 0.25
2929
loop = false
3030
step = 0.05
3131
tracks/0/type = "value"
32-
tracks/0/path = NodePath("Pivot/Sprite:self_modulate")
32+
tracks/0/path = NodePath("Sprite:self_modulate")
3333
tracks/0/interp = 1
3434
tracks/0/loop_wrap = true
3535
tracks/0/imported = false
@@ -41,7 +41,7 @@ tracks/0/keys = {
4141
"values": [ Color( 1, 1, 1, 1 ), Color( 1, 0.9375, 0, 1 ), Color( 1, 1, 1, 1 ) ]
4242
}
4343
tracks/1/type = "value"
44-
tracks/1/path = NodePath("Pivot/Sprite:position")
44+
tracks/1/path = NodePath("Sprite:position")
4545
tracks/1/interp = 1
4646
tracks/1/loop_wrap = true
4747
tracks/1/imported = false
@@ -53,7 +53,7 @@ tracks/1/keys = {
5353
"values": [ Vector2( 1.43051e-06, -1.90735e-06 ), Vector2( 1.43051e-06, -1.90735e-06 ), Vector2( 0, -20 ), Vector2( 1.43051e-06, -1.90735e-06 ) ]
5454
}
5555
tracks/2/type = "value"
56-
tracks/2/path = NodePath("Pivot/Sprite:scale")
56+
tracks/2/path = NodePath("Sprite:scale")
5757
tracks/2/interp = 1
5858
tracks/2/loop_wrap = true
5959
tracks/2/imported = false
@@ -96,11 +96,7 @@ playback/active = false
9696
playback/repeat = false
9797
playback/speed = 1.0
9898

99-
[node name="Pivot" type="Position2D" parent="." index="2"]
100-
101-
_sections_unfolded = [ "Transform" ]
102-
103-
[node name="Sprite" type="Sprite" parent="Pivot" index="0"]
99+
[node name="Sprite" type="Sprite" parent="." index="2"]
104100

105101
position = Vector2( 1.43051e-06, -1.90735e-06 )
106102
texture = ExtResource( 2 )

2018/06-09-grid-based-movement/pawns/actor.gd

+7-3
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ func get_input_direction():
2424
)
2525

2626
func update_look_direction(direction):
27-
$Pivot/Sprite.rotation = direction.angle()
27+
$Sprite.rotation = direction.angle()
2828

2929
func move_to(target_position):
3030
set_process(false)
@@ -33,8 +33,12 @@ func move_to(target_position):
3333
# Move the node to the target cell instantly,
3434
# and animate the sprite moving from the start to the target cell
3535
var move_direction = (target_position - position).normalized()
36-
$Tween.interpolate_property($Pivot, "position", - move_direction * 32, Vector2(), $AnimationPlayer.current_animation_length, Tween.TRANS_LINEAR, Tween.EASE_IN)
37-
position = target_position
36+
37+
$Tween.interpolate_property(
38+
self,"position",
39+
position,target_position,
40+
$AnimationPlayer.current_animation_length,
41+
Tween.TRANS_LINEAR, Tween.EASE_IN)
3842

3943
$Tween.start()
4044

0 commit comments

Comments
 (0)