# What's wrong with my math?

Get help using Construct 2

### » 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
B
34
S
14
G
4
Posts: 251
Reputation: 4,074

### » 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
B
179
S
50
G
208
Posts: 8,724
Reputation: 128,816

### » Thu Nov 01, 2012 11:32 pm

But aren't the angles for sin & cos the same in my capx?
B
34
S
14
G
4
Posts: 251
Reputation: 4,074

### » Thu Nov 01, 2012 11:47 pm

You used angle(), but you need that to either increase, or decrease.
B
179
S
50
G
208
Posts: 8,724
Reputation: 128,816

### » 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