What's wrong with my math?

0 favourites
  • 5 posts
From the Asset Store
Be quick and choose whether the shown equation is right or wrong.
  • 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

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • 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.

  • But aren't the angles for sin & cos the same in my capx?

  • You used angle(), but you need that to either increase, or decrease.

  • 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.

    <img src="https://dl.dropbox.com/u/53374990/Forum/orbit.png" border="0" />

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)