Advertisement
Guest User

Untitled

a guest
Nov 27th, 2020
58
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
GDScript 0.73 KB | None
  1. extends Node2D
  2.  
  3. var points_array = PoolVector2Array([])
  4.  
  5. func _ready():
  6.     generate_random_points()
  7.     update()
  8.     draw_this_polygonshape()
  9.  
  10.  
  11. func generate_random_points():
  12.     randomize()
  13.     for i in range(5):
  14.         points_array.append(Vector2(randi()%100+200, randi()%100+200))
  15.  
  16. func _draw():
  17.     var i = 0
  18.     while i < points_array.size()-1:
  19.         draw_line(points_array[i], points_array[i+1], Color.black)
  20.         i+=1
  21.     draw_line(points_array[i], points_array[0], Color.black)
  22.  
  23.  
  24. func draw_this_polygonshape():
  25.     var polygon_collision = CollisionPolygon2D.new()
  26.     for point in points_array:
  27.         polygon_collision.polygon.append(point)
  28.     var polygon_body = RigidBody2D.new()
  29.     polygon_body.add_child(polygon_collision)
  30.     self.add_child(polygon_body)
Advertisement
RAW Paste Data Copied
Advertisement