Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- extends Node2D
- var points_array = PoolVector2Array([])
- func _ready():
- generate_random_points()
- update()
- draw_this_polygonshape()
- func generate_random_points():
- randomize()
- for i in range(5):
- points_array.append(Vector2(randi()%100+200, randi()%100+200))
- func _draw():
- var i = 0
- while i < points_array.size()-1:
- draw_line(points_array[i], points_array[i+1], Color.black)
- i+=1
- draw_line(points_array[i], points_array[0], Color.black)
- func draw_this_polygonshape():
- var polygon_collision = CollisionPolygon2D.new()
- for point in points_array:
- polygon_collision.polygon.append(point)
- var polygon_body = RigidBody2D.new()
- polygon_body.add_child(polygon_collision)
- self.add_child(polygon_body)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement