Skip to content

Commit a6ce6db

Browse files
Toshiwozakien-mga
authored andcommitted
Updated 2D pathfinding for version 3.1 (#301)
1 parent 916c9c9 commit a6ce6db

File tree

10 files changed

+32
-135
lines changed

10 files changed

+32
-135
lines changed

2d/navigation_astar/Game.tscn

Lines changed: 4 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -5,39 +5,18 @@
55
[ext_resource path="res://character.gd" type="Script" id=3]
66
[ext_resource path="res://sprites/character.png" type="Texture" id=4]
77

8-
[node name="Game" type="Node" index="0"]
8+
[node name="Game" type="Node"]
99

10-
[node name="TileMap" type="TileMap" parent="." index="0"]
11-
12-
mode = 0
10+
[node name="TileMap" type="TileMap" parent="."]
1311
tile_set = ExtResource( 1 )
14-
cell_size = Vector2( 64, 64 )
15-
cell_quadrant_size = 16
16-
cell_custom_transform = Transform2D( 1, 0, 0, 1, 0, 0 )
17-
cell_half_offset = 2
18-
cell_tile_origin = 0
19-
cell_y_sort = false
20-
cell_clip_uv = false
21-
collision_use_kinematic = false
22-
collision_friction = 1.0
23-
collision_bounce = 0.0
24-
collision_layer = 1
25-
collision_mask = 1
26-
occluder_light_mask = 1
2712
format = 1
2813
tile_data = PoolIntArray( 65537, 0, 0, 65541, 0, 0, 65545, 0, 0, 65550, 0, 0, 196614, 0, 0, 196615, 0, 0, 196616, 0, 0, 196617, 0, 0, 196618, 0, 0, 196619, 0, 0, 262145, 0, 0, 262146, 0, 0, 262147, 0, 0, 327683, 0, 0, 393219, 0, 0, 393220, 0, 0, 393221, 0, 0, 393222, 0, 0, 393226, 0, 0, 393227, 0, 0, 393228, 0, 0, 458761, 0, 0, 524290, 0, 0, 524291, 0, 0, 524292, 0, 0, 524293, 0, 0, 524294, 0, 0, 524295, 0, 0, 524296, 0, 0, 524297, 0, 0 )
2914
script = ExtResource( 2 )
30-
_sections_unfolded = [ "Cell" ]
31-
map_size = Vector2( 16, 16 )
32-
33-
[node name="Character" type="Position2D" parent="." index="1"]
3415

16+
[node name="Character" type="Position2D" parent="."]
3517
script = ExtResource( 3 )
36-
SPEED = 200.0
37-
38-
[node name="Sprite" type="Sprite" parent="Character" index="0"]
3918

19+
[node name="Sprite" type="Sprite" parent="Character"]
4020
position = Vector2( 7, 0 )
4121
texture = ExtResource( 4 )
4222

43-

2d/navigation_astar/character.gd

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,14 @@ var target_position = Vector2()
1212
var velocity = Vector2()
1313

1414
func _ready():
15-
_change_state(IDLE)
15+
_change_state(STATES.IDLE)
1616

1717

1818
func _change_state(new_state):
19-
if new_state == FOLLOW:
20-
path = get_parent().get_node('TileMap').get_path(position, target_position)
19+
if new_state == STATES.FOLLOW:
20+
path = get_parent().get_node('TileMap')._get_path(position, target_position)
2121
if not path or len(path) == 1:
22-
_change_state(IDLE)
22+
_change_state(STATES.IDLE)
2323
return
2424
# The index 0 is the starting cell
2525
# we don't want the character to move back to it in this example
@@ -28,13 +28,13 @@ func _change_state(new_state):
2828

2929

3030
func _process(delta):
31-
if not _state == FOLLOW:
31+
if not _state == STATES.FOLLOW:
3232
return
3333
var arrived_to_next_point = move_to(target_point_world)
3434
if arrived_to_next_point:
3535
path.remove(0)
3636
if len(path) == 0:
37-
_change_state(IDLE)
37+
_change_state(STATES.IDLE)
3838
return
3939
target_point_world = path[0]
4040

@@ -57,4 +57,4 @@ func _input(event):
5757
global_position = get_global_mouse_position()
5858
else:
5959
target_position = get_global_mouse_position()
60-
_change_state(FOLLOW)
60+
_change_state(STATES.FOLLOW)

2d/navigation_astar/default_env.tres

Lines changed: 0 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -2,100 +2,15 @@
22

33
[sub_resource type="ProceduralSky" id=1]
44

5-
radiance_size = 4
65
sky_top_color = Color( 0.0470588, 0.454902, 0.976471, 1 )
76
sky_horizon_color = Color( 0.556863, 0.823529, 0.909804, 1 )
87
sky_curve = 0.25
9-
sky_energy = 1.0
108
ground_bottom_color = Color( 0.101961, 0.145098, 0.188235, 1 )
119
ground_horizon_color = Color( 0.482353, 0.788235, 0.952941, 1 )
1210
ground_curve = 0.01
13-
ground_energy = 1.0
14-
sun_color = Color( 1, 1, 1, 1 )
15-
sun_latitude = 35.0
16-
sun_longitude = 0.0
17-
sun_angle_min = 1.0
18-
sun_angle_max = 100.0
19-
sun_curve = 0.05
20-
sun_energy = 16.0
21-
texture_size = 2
2211

2312
[resource]
2413

2514
background_mode = 2
2615
background_sky = SubResource( 1 )
27-
background_sky_custom_fov = 0.0
28-
background_color = Color( 0, 0, 0, 1 )
29-
background_energy = 1.0
30-
background_canvas_max_layer = 0
31-
ambient_light_color = Color( 0, 0, 0, 1 )
32-
ambient_light_energy = 1.0
33-
ambient_light_sky_contribution = 1.0
34-
fog_enabled = false
35-
fog_color = Color( 0.5, 0.6, 0.7, 1 )
36-
fog_sun_color = Color( 1, 0.9, 0.7, 1 )
37-
fog_sun_amount = 0.0
38-
fog_depth_enabled = true
39-
fog_depth_begin = 10.0
40-
fog_depth_curve = 1.0
41-
fog_transmit_enabled = false
42-
fog_transmit_curve = 1.0
43-
fog_height_enabled = false
44-
fog_height_min = 0.0
45-
fog_height_max = 100.0
46-
fog_height_curve = 1.0
47-
tonemap_mode = 0
48-
tonemap_exposure = 1.0
49-
tonemap_white = 1.0
50-
auto_exposure_enabled = false
51-
auto_exposure_scale = 0.4
52-
auto_exposure_min_luma = 0.05
53-
auto_exposure_max_luma = 8.0
54-
auto_exposure_speed = 0.5
55-
ss_reflections_enabled = false
56-
ss_reflections_max_steps = 64
57-
ss_reflections_fade_in = 0.15
58-
ss_reflections_fade_out = 2.0
59-
ss_reflections_depth_tolerance = 0.2
60-
ss_reflections_roughness = true
61-
ssao_enabled = false
62-
ssao_radius = 1.0
63-
ssao_intensity = 1.0
64-
ssao_radius2 = 0.0
65-
ssao_intensity2 = 1.0
66-
ssao_bias = 0.01
67-
ssao_light_affect = 0.0
68-
ssao_color = Color( 0, 0, 0, 1 )
69-
ssao_quality = 0
70-
ssao_blur = 3
71-
ssao_edge_sharpness = 4.0
72-
dof_blur_far_enabled = false
73-
dof_blur_far_distance = 10.0
74-
dof_blur_far_transition = 5.0
75-
dof_blur_far_amount = 0.1
76-
dof_blur_far_quality = 1
77-
dof_blur_near_enabled = false
78-
dof_blur_near_distance = 2.0
79-
dof_blur_near_transition = 1.0
80-
dof_blur_near_amount = 0.1
81-
dof_blur_near_quality = 1
82-
glow_enabled = false
83-
glow_levels/1 = false
84-
glow_levels/2 = false
85-
glow_levels/3 = true
86-
glow_levels/4 = false
87-
glow_levels/5 = true
88-
glow_levels/6 = false
89-
glow_levels/7 = false
90-
glow_intensity = 0.8
91-
glow_strength = 1.0
92-
glow_bloom = 0.0
93-
glow_blend_mode = 2
94-
glow_hdr_threshold = 1.0
95-
glow_hdr_scale = 2.0
96-
glow_bicubic_upscale = false
97-
adjustment_enabled = false
98-
adjustment_brightness = 1.0
99-
adjustment_contrast = 1.0
100-
adjustment_saturation = 1.0
10116

2d/navigation_astar/icon.png.import

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,14 @@ path="res://.import/icon.png-487276ed1e3a0c39cad0279d744ee560.stex"
77
[deps]
88

99
source_file="res://icon.png"
10-
source_md5="0b0cb045ce690875fab066adeea76aba"
11-
1210
dest_files=[ "res://.import/icon.png-487276ed1e3a0c39cad0279d744ee560.stex" ]
13-
dest_md5="58323f97585db7bd8d6e03320f9ebb33"
1411

1512
[params]
1613

1714
compress/mode=0
1815
compress/lossy_quality=0.7
1916
compress/hdr_mode=0
17+
compress/bptc_ldr=0
2018
compress/normal_map=0
2119
flags/repeat=0
2220
flags/filter=true
@@ -26,6 +24,7 @@ flags/srgb=2
2624
process/fix_alpha_border=true
2725
process/premult_alpha=false
2826
process/HDR_as_SRGB=false
27+
process/invert_color=false
2928
stream=false
3029
size_limit=0
3130
detect_3d=true

2d/navigation_astar/pathfind_astar.gd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ func calculate_point_index(point):
111111
return point.x + map_size.x * point.y
112112

113113

114-
func get_path(world_start, world_end):
114+
func _get_path(world_start, world_end):
115115
self.path_start_position = world_to_map(world_start)
116116
self.path_end_position = world_to_map(world_end)
117117
_recalculate_path()

2d/navigation_astar/project.godot

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,12 @@
66
; [section] ; section goes between []
77
; param=value ; assign values to parameters
88

9-
config_version=3
9+
config_version=4
10+
11+
_global_script_classes=[ ]
12+
_global_script_class_icons={
13+
14+
}
1015

1116
[application]
1217

@@ -16,8 +21,11 @@ config/icon="res://icon.png"
1621

1722
[input]
1823

19-
click=[ Object(InputEventMouseButton,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"button_mask":0,"position":Vector2( 0, 0 ),"global_position":Vector2( 0, 0 ),"factor":1.0,"button_index":1,"pressed":false,"doubleclick":false,"script":null)
24+
click={
25+
"deadzone": 0.5,
26+
"events": [ Object(InputEventMouseButton,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"button_mask":0,"position":Vector2( 0, 0 ),"global_position":Vector2( 0, 0 ),"factor":1.0,"button_index":1,"pressed":false,"doubleclick":false,"script":null)
2027
]
28+
}
2129

2230
[rendering]
2331

2d/navigation_astar/sprites/character.png.import

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,14 @@ path="res://.import/character.png-eb70ac48a5acf508c4b7740ea4ac4fae.stex"
77
[deps]
88

99
source_file="res://sprites/character.png"
10-
source_md5="8746d76344ac3bad60c33b1bc43e11fd"
11-
1210
dest_files=[ "res://.import/character.png-eb70ac48a5acf508c4b7740ea4ac4fae.stex" ]
13-
dest_md5="e874204705e06ca4dc2c9b0a90db7e8a"
1411

1512
[params]
1613

1714
compress/mode=0
1815
compress/lossy_quality=0.7
1916
compress/hdr_mode=0
17+
compress/bptc_ldr=0
2018
compress/normal_map=0
2119
flags/repeat=0
2220
flags/filter=true
@@ -26,6 +24,7 @@ flags/srgb=2
2624
process/fix_alpha_border=true
2725
process/premult_alpha=false
2826
process/HDR_as_SRGB=false
27+
process/invert_color=false
2928
stream=false
3029
size_limit=0
3130
detect_3d=true

2d/navigation_astar/sprites/obstacle.png.import

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,14 @@ path="res://.import/obstacle.png-0258c5f5ce65bfa0dd8610adeb784f54.stex"
77
[deps]
88

99
source_file="res://sprites/obstacle.png"
10-
source_md5="f741dc1724960a029cba51c962d988be"
11-
1210
dest_files=[ "res://.import/obstacle.png-0258c5f5ce65bfa0dd8610adeb784f54.stex" ]
13-
dest_md5="432d869b849ac70d4f76935622b2e37b"
1411

1512
[params]
1613

1714
compress/mode=0
1815
compress/lossy_quality=0.7
1916
compress/hdr_mode=0
17+
compress/bptc_ldr=0
2018
compress/normal_map=0
2119
flags/repeat=0
2220
flags/filter=true
@@ -26,6 +24,7 @@ flags/srgb=2
2624
process/fix_alpha_border=true
2725
process/premult_alpha=false
2826
process/HDR_as_SRGB=false
27+
process/invert_color=false
2928
stream=false
3029
size_limit=0
3130
detect_3d=true

2d/navigation_astar/sprites/path_end.png.import

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,14 @@ path="res://.import/path_end.png-02b79e25892cd8d863bd44c3c5a1720e.stex"
77
[deps]
88

99
source_file="res://sprites/path_end.png"
10-
source_md5="be9537ddfec33fdc35a33d88cad94d38"
11-
1210
dest_files=[ "res://.import/path_end.png-02b79e25892cd8d863bd44c3c5a1720e.stex" ]
13-
dest_md5="436b174ce46135e1d4d6b9b238889433"
1411

1512
[params]
1613

1714
compress/mode=0
1815
compress/lossy_quality=0.7
1916
compress/hdr_mode=0
17+
compress/bptc_ldr=0
2018
compress/normal_map=0
2119
flags/repeat=0
2220
flags/filter=true
@@ -26,6 +24,7 @@ flags/srgb=2
2624
process/fix_alpha_border=true
2725
process/premult_alpha=false
2826
process/HDR_as_SRGB=false
27+
process/invert_color=false
2928
stream=false
3029
size_limit=0
3130
detect_3d=true

2d/navigation_astar/sprites/path_start.png.import

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,14 @@ path="res://.import/path_start.png-475bd0b469629aa8779d506c5134e5c2.stex"
77
[deps]
88

99
source_file="res://sprites/path_start.png"
10-
source_md5="6b4a1211e21f4fab937c7b309d802a44"
11-
1210
dest_files=[ "res://.import/path_start.png-475bd0b469629aa8779d506c5134e5c2.stex" ]
13-
dest_md5="5d90014ca7f70fa5f9494bd25fbe72d0"
1411

1512
[params]
1613

1714
compress/mode=0
1815
compress/lossy_quality=0.7
1916
compress/hdr_mode=0
17+
compress/bptc_ldr=0
2018
compress/normal_map=0
2119
flags/repeat=0
2220
flags/filter=true
@@ -26,6 +24,7 @@ flags/srgb=2
2624
process/fix_alpha_border=true
2725
process/premult_alpha=false
2826
process/HDR_as_SRGB=false
27+
process/invert_color=false
2928
stream=false
3029
size_limit=0
3130
detect_3d=true

0 commit comments

Comments
 (0)