What's wrong with my math?

Get help using Construct 2

Post » Thu Nov 01, 2012 10:47 pm

I'm trying to make this blue box orbit the red box using Cos & Sin, however the distance between the boxes is increasing.

Why? Shouldn't it stay the same distance away?


capx
Follow me on Twitter @evgLabs
B
33
S
14
G
4
Posts: 251
Reputation: 4,049

Post » Thu Nov 01, 2012 11:15 pm

You want the angle you put into cos, and sin to be the same, and a value between 0, and 360. Use a variable and implement a counter to add to that variable.
Also you want to use the object that you want to rotate around as the x, and y.
Sprite.X+Cos(yourvariable)*distance(self.x,self.y,sprite.x,sprite.y)

Sprite.Y+Sos(yourvariable)*distance(self.x,self.y,sprite.x,sprite.y)
Then set yourvariable using the variable + something *dt.

Note it will probably work if you go beyond 360, but you can always use %360 as a limiter.newt2012-11-01 23:23:33
Image Image
B
161
S
48
G
90
Posts: 7,347
Reputation: 66,749

Post » Thu Nov 01, 2012 11:32 pm

But aren't the angles for sin & cos the same in my capx?
Follow me on Twitter @evgLabs
B
33
S
14
G
4
Posts: 251
Reputation: 4,049

Post » Thu Nov 01, 2012 11:47 pm

You used angle(), but you need that to either increase, or decrease.
Image Image
B
161
S
48
G
90
Posts: 7,347
Reputation: 66,749

Post » Fri Nov 02, 2012 12:25 am

The reason the distance was increasing is because on every single tick it moves in a straight line that is 90 degrees from the direction to the centre.. In a sense it's not truly curved, the angle is just corrected 60 times a second.

Imagine what happens on a single tick, and if that distance was 200 pixels instead.. i think that makes it easier to see why it's moving further away from centre.. i hope .. I can totally understand the confusion though.


edit: you should try something like this, it's more or less what newt was saying.
keepee2012-11-02 00:29:25
B
28
S
8
G
1
Posts: 469
Reputation: 4,683


Return to How do I....?

Who is online

Users browsing this forum: Aphrodite, Yahoo [Bot] and 20 guests