forked from godotengine/godot
-
Notifications
You must be signed in to change notification settings - Fork 0
PolygonPathFinder Demo GD Script
ScyDev edited this page Jan 13, 2015
·
5 revisions
demo finding path from f to t.
+-------+--------+
| +------+ |
| | | |
| f | | t |
| | | |
| +------+ |
+----------------+
extends Spatial
func _ready():
var pf = PolygonPathFinder.new()
var points = Vector2Array()
var connections = IntArray()
# poly 1
points.push_back(Vector2(0, 0)) #0
points.push_back(Vector2(10, 0)) #1
points.push_back(Vector2(10, 10)) #2
points.push_back(Vector2(0, 10)) #3
connections.push_back(0) # connect vertex 0 ...
connections.push_back(1) # ... to 1
connections.push_back(1) # connect vertex 1 ...
connections.push_back(2) # ... to 2
connections.push_back(2) # etc.
connections.push_back(3)
connections.push_back(3) # connect vertex 3 ...
connections.push_back(0) # back to vertex 0, to close the polygon
# poly 2, as obstacle inside poly 1
points.push_back(Vector2(2, 0.5)) #4
points.push_back(Vector2(4, 0.5)) #5
points.push_back(Vector2(4, 9.5)) #6
points.push_back(Vector2(2, 9.5)) #7
connections.push_back(4)
connections.push_back(5)
connections.push_back(5)
connections.push_back(6)
connections.push_back(6)
connections.push_back(7)
connections.push_back(7)
connections.push_back(4)
print("points: ",points)
print("connections: ",connections)
pf.setup(points, connections)
var path = pf.find_path(Vector2(1, 5), Vector2(8, 5))
print("path: ",path)
for step in path:
print("step: ",step)