Rotate around point

New releases and general discussions.

Post » Fri May 15, 2009 7:36 pm

Rotate around x,y

Sometimes you just need to rotate around something else.
pretty please?
B
3
S
2
G
4
Posts: 1,445
Reputation: 4,665

Post » Fri May 15, 2009 7:47 pm

To rotate an object A degrees around point P:

Set 'distance' to distance(Object.X, Object.Y, P.X, P.Y)
Set 'angle' to angle(Object.X, Object.Y, P.X, P.Y)

Set X to P.X + cos(angle + A) * distance
Set Y to P.Y + sin(angle + A) * distance

Haven't checked that but I think it's right...
Scirra Founder
B
359
S
214
G
72
Posts: 22,946
Reputation: 178,528

Post » Sat May 16, 2009 3:43 am

yea, pretty sure thats it. you can also use another sprite if it makes it any easier. make a 4x1 px sprite with the action point on one side, then put an image point on the other side. then set the object position to the image point and rotate the rotate-helper sprite. The distance is rotate-helper.width (just thought of this now, actually seems like a pretty useful idea :mrgreen: ).
B
25
S
3
G
6
Posts: 1,197
Reputation: 5,620


Return to Construct Classic Discussion

Who is online

Users browsing this forum: No registered users and 3 guests