0 votes

Im making aoe skill visualization system and im using custom functions to create the polygons. I cant use _draw(). So Im creating polygons from points and adding them as a child. But I cant rotate a polygon2d. So I decided to add polygons to node2d as a child and rotate the node. But I cant synhronise node rotation with center point of my polygon. Can someone suggest me rotation method or better way to do it (I know about sprites, but i think its more flexible method than endless sprite redrawing)?

Polygon generation function:

func generate_arc_poly(angle, radius, start_position, finish_position, color: Color):
var arc_points = 30
var polygon = Polygon2D.new()
var points: PoolVector2Array
var direction = start_position.direction_to(finish_position) #get normilised direction
var central_point = direction * radius #get central Vector with radius lenght
var angle_delta: float = deg2rad(angle) / arc_points #calculating 1 step rotation angle
var compensate_angle: float = deg2rad(-angle) / 2
var vector: Vector2 = central_point

vector = vector.rotated(compensate_angle) #rotating to compensate starting point

for point in arc_points:
    points.append(vector + start_position)
    vector = vector.rotated(angle_delta) 
polygon.color = color

return polygon

Polygon creation and adding to the scene:

func aoe_vis_setup(leader, effects, parameters):
var polygon = effects[1].call_funcv(parameters)
var skill_visualise = Node2D.new()

Parameters wich i pass to the function: [90, 50, Vector2(0,8), Color(0,0,100,0.05)]

And look_at function wich rotates Node2D:

for polygon in visualization:
        var mouse_position =  leader.get_global_mouse_position()
Godot version Godot Engine v3.5.1
in Engine by (12 points)

Please log in or register to answer this question.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.