Sine circle

For questions about using Classic.

Post » Mon Jul 11, 2011 11:10 pm

Hey chaps

I am trying to make a circle path using sine on the x and y axis.
Thanks to Shviller, I know that, using the sine behaviour I can achieve this with a 25% offset on one axis. However I want to use events to control it, and I just can't get the timing right, I am not sure how to offset the values with events.

sin(timer*0.10) * 10

So I have something along these lines, and have tried all sorts of combinations of values.

sin(timer*0.025) * 10
sin(timer*0.025) * 2.5
sin(timer*0.10) * 2.5

So I am thinking that the offset is some other value, but I am not sure.

Anyone have any ideas?

B
9
S
2
G
4
Posts: 346
Reputation: 2,726

Post » Mon Jul 11, 2011 11:52 pm

cos and sin expect a value in degree and return a value based on the unit circle (so they return [-1,+1])

To position something on a circle around a center:

x = center_X + cos(angle) * radius
y = center_Y + sin(angle) * radius

To move something circular around a center over time:

angle = angle + amountofchangepersecond * TimeDelta
x = center_X + cos(angle) * radius
y = center_Y + sin(angle) * radius

You may also change angle and/or radius independently for x and y which will have various effects, like shaping an ellipse instead of a circle and much more.tulamide2011-07-11 23:53:03
Image
B
23
S
8
G
10
Posts: 1,820
Reputation: 8,242

Post » Tue Jul 12, 2011 12:46 am

Oh you are absolutely fantastic Tulamide, always so helpful. I was specifically looking for elliptical shapes as well. Cheers!
B
9
S
2
G
4
Posts: 346
Reputation: 2,726

Post » Thu Oct 23, 2014 9:09 pm

@tulamide - lets say you have a square moving around the elliptical path, how do you angle it to aim always at the center?
B
50
S
21
G
8
Posts: 844
Reputation: 10,299

Post » Fri Oct 24, 2014 5:30 am

That depends on the exact situation. In the example above, I made 3years ago, the angle is from the center's point of view. In this case it is easy: Just use the opposite angle. Easiest way to do so is by adding 180:

angle = angle + amountofchangepersecond * TimeDelta
x = center_X + cos(angle) * radius
y = center_Y + sin(angle) * radius
square_angle = angle + 180
Image
B
23
S
8
G
10
Posts: 1,820
Reputation: 8,242


Return to Help & Support using Construct Classic

Who is online

Users browsing this forum: No registered users and 2 guests