#Rotating coordinate by 90 degrees
10 messages · Page 1 of 1 (latest)
I tried to write a function (it doesn't work) but this is where I got to.
var half_length = length/2
var half_height = height/2
x -= half_length
y -= half_height
var dist = Vector2(0, 0).distance_to(Vector2(x, y))
var new_y = sin(angle)*dist
var new_x = cos(angle)*dist
return Vector2(new_x+half_length, new_y+half_height)```
What you need is this vector
Consider your image center is (4,4), in the first image the vector is (1,-3), the second image it is (3, 1), flipped the x-y and adjust the positive/negative accordingly
Something like this:
var center = Vector2(width / 2, height / 2)
var vec = Vector2(x, y) - center
return center + vec.rotated(angle)```
If you want something general purpose that works with any angle
🤦♂️ I forgot about the rotated() function
return Vector2(round(ret.x), round(ret.y))```
Solved, it didn't work for a while, but after doing this it works perfectly.
Thank you Nisovin!
If you're always rotating 90 degrees, then you should just do what the person above said, and do the x/y swap