Skip to content

Commit 2be89f3

Browse files
committed
Simple Character: Add value block for Direction X
So users can check where the character is heading: * -1: to the left * 1: to the right * 0: not moving
1 parent 3b78183 commit 2be89f3

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

addons/block_code/simple_nodes/simple_character/simple_character.gd

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ var collision: CollisionShape2D
3838
var gravity = ProjectSettings.get_setting("physics/2d/default_gravity")
3939

4040
var _jumping = false
41+
var direction_x: int = 0
4142

4243

4344
func _set_texture(new_texture):
@@ -100,6 +101,7 @@ func _player_input_to_direction(player: String):
100101

101102
func move_with_player_buttons(player: String, kind: String, delta: float):
102103
var direction = _player_input_to_direction(player)
104+
direction_x = direction.x
103105

104106
if kind == "top-down":
105107
velocity = direction * speed
@@ -153,13 +155,22 @@ static func setup_custom_blocks():
153155
"name": "speed",
154156
"type": TYPE_VECTOR2,
155157
},
158+
{
159+
"name": "direction_x",
160+
"type": TYPE_INT,
161+
},
156162
]
157163

158164
var property_settings = {
159165
"speed":
160166
{
161167
"category": "Physics | Velocity",
162168
},
169+
"direction_x":
170+
{
171+
"category": "Physics | Velocity",
172+
"has_setter": false,
173+
},
163174
}
164175

165176
BlocksCatalog.add_custom_blocks(_class_name, block_list, property_list, property_settings)

0 commit comments

Comments
 (0)