Hi, I was wondering how I could have objects (in a grid) rotate relative to a center point.
Its a jigsaw puzzle, i'm trying to have piece groups be able to rotate.
I think my issue is i'm trying to do it without storing a "real" x,y offsets for each piece (to apply rotation upon)
I feel like the way I went about it falls apart because I try (and fail) to generate the current offsets based on the current positions and apply rotation to it and it doesn't work. (the relative distances do, but are not synced to the right angles, in fact it feels random)
static rotate_angle = function(_angle)
{
var _origin_x = x,
_origin_y = y;
for (var i = 0; i < array_length(pieces); i++)
{
var _dist = point_distance(_origin_x, _origin_y, pieces[i].x, pieces[i].y);
var _pdir = point_direction(_origin_x, _origin_y, pieces[i].x, pieces[i].y);
var offset_x = lengthdir_x(_dist, _pdir),
offset_y = lengthdir_y(_dist, _pdir);
pieces[i].x = x + lengthdir_x(offset_x , angle) + lengthdir_x(offset_y , angle - 90)
pieces[i].y = y + lengthdir_y(offset_x , angle) + lengthdir_y(offset_y , angle - 90)
}
}
Please help, thanks!