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 3, 2015
·
5 revisions
'''
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
#points.push_back(Vector2(0, 0)) #0 # don't duplicate vertices
connections.push_back(0)
connections.push_back(1)
connections.push_back(1)
connections.push_back(2)
connections.push_back(2)
connections.push_back(3)
connections.push_back(3)
connections.push_back(0)
# poly 2
#points.push_back(Vector2(10, 0)) #1
points.push_back(Vector2(20, 0)) #4
points.push_back(Vector2(20, 10)) #5
#points.push_back(Vector2(10, 10)) #2
#points.push_back(Vector2(10, 0)) #1
connections.push_back(1)
connections.push_back(4)
connections.push_back(4)
connections.push_back(5)
connections.push_back(5)
connections.push_back(2)
connections.push_back(2)
connections.push_back(1)
# poly 3
#points.push_back(Vector2(10, 10)) #2
#points.push_back(Vector2(20, 10)) #5
points.push_back(Vector2(20, 20)) #6
points.push_back(Vector2(10, 20)) #7
#points.push_back(Vector2(10, 10)) #2
connections.push_back(2)
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(2)
print("points: ",points)
print("connections: ",connections)
pf.setup(points, connections)
var path = pf.find_path(Vector2(2, 8), Vector2(17, 19))
print("path: ",path)
for step in path:
print("step: ",step)
'''