Hello,
I’m trying to rotate object around another object or arond center.
I’m working with this mathematical formula:
x′=xcosθ−ysinθ
y′=ycosθ+xsinθ
I know there are more efective ways, but I need do it like this, the reason is difficult to explain.
I programmed it in Defold with this code:
pos = vmath.vector3()
pos = go.get_position()
pos1 = go.get_position()
center = go.get_position("center")
pos.x = (center.x - pos1.x) * math.cos(math.rad(90)) - (center.y - pos1.y) * math.sin(math.rad(90))
pos.y = (center.y - pos1.y) * math.cos(math.rad(90)) + (center.x - pos1.x) * math.sin(math.rad(90))
print(pos)
go.set_position(pos)
The most important part of code is there:
pos.x = (center.x - pos1.x) * math.cos(math.rad(90)) - (center.y - pos1.y) * math.sin(math.rad(90))
pos.y = (center.y - pos1.y) * math.cos(math.rad(90)) + (center.x - pos1.x) * math.sin(math.rad(90))
But it doesn’t work as I want. Does anybody know why?
Thank you for every answer.