Edit: I've clearly done something wrong trying to format the code. I've a lesson to teach so I'll have to fix it later. Sorry!
I apologize if this is a really daft question, I'm very new to programming. I'm trying to put together something to help me explain exterior angles of polygons to my students.
It would let them create/pick a polygon and have a sprite walk around the outside of it, tracing out exterior angles as he goes. I've got a decent idea of how I'm going to do most of it, but I can't for the life of me figure out how to work with the vertices of the polygon.
I've defined a polygon2D called Quadrilateral to test. Defined a variable for each Vector2 in Quadrilateral.polygon[n] and used the Vector2s to determine the position of a sprite. The problem is, the sprite never lines up with the vertices. I've tried using both .position and .global_position and neither lines it up correctly.
func trace():
# Set the coordinates of the polygon.
# Eventually will take inputs from a control
Quadrilateral.polygon[0] = Vector2(100,200)
Quadrilateral.polygon[1] = Vector2(100,100)
Quadrilateral.polygon[2] = Vector2(200,100)
Quadrilateral.polygon[3] = Vector2(200,200)
# Set variables for each vertex
var Vertex1 : Vector2 = Quadrilateral.polygon[0]
var Vertex2 : Vector2 = Quadrilateral.polygon[1]
var Vertex3 : Vector2 = Quadrilateral.polygon[2]
var Vertex4 : Vector2 = Quadrilateral.polygon[3]
# Move spirte (Pointer) to the coordinates of vertex 1
Pointer.global_position = Vertex1
# $Label to output coords for troubleshooting, does not affect code.
$Label.text = str(Vertex1, Vertex2, Pointer.position.x, Pointer.position.y)
I have a hunch that my issue is that I'm not using the global coordinates for the vertices of the polygon but I have no idea on how I would do that.