If you really want to go into the mathmatics @Flying_Fajita, then lets buckle up because I’m going to explain what all the expressions are used for in my Orbit example! I’m going to go in detail, double-check my math, and learn a few things myself because I got some help with this system… so expect changes in the code too.
Math.atan2(A,B)
What you saw was atan2 was just used for the AngleTo bundle, which is also another example I have that gets the angle between 2 objects. (Angle-To Example). What atan2 does is that it gives the angle compare to the origin.
Like what is the angle (X,Y) from (0,0)?
Example: atan2 (X,Y) = Radian
Example2: atan2 (5,5) = 0.785398 (or 45 degrees)
The expression in the AngleTo bundle is this:
90-(Math.atan2(A,B)/Math.PI) * 180
where
A = Target X - This X
B = Target Y - This Y
Orbit Bundle:
Degree to Radian: (This is now updated into the example)
If you input degree’s, it gets changed into radian by using (Degree × π/180). As well in the expression, you can see I multiplied by 1000 so you can have more speed options. For example 0 - 1000 is a good range of speed, but you can also go over 1000. And another note, since Flowlab now allows decimal numbers, I may lower the range to 100 instead to have similar speeds to velocity (in the future).
Speed:
The speed is the Radian (angle) + speed in which outputs a NEW angle. The expression is looped where the speed is continuously adding speed to the new angle.
X and Y Positions:
After Speed gives us a new angle, we convert that angle to an X position by using cos(new angle / 1000). To get the Y position, we want to use sine instead of cos. I divide by 1000 because the angle I used to change degrees to radians is being multiplied by 1000.
Distance:
After cos and sine, we multiply how many pixels away from the center.
Think of it like the Angle * the Distance.
Center the X and Y Positions:
After we added our distance into the equation, we just need to update to the center of where we want to orbit! This is Simple as Result X + Target X or Result Y + Target Y.
Just make the Speed add a new angle every frame and we have an Orbit!
Angle + Speed = (Position x Distance) + Center Position
And that’s it, the Orbit is basically just updating the position around the object. This also has many more uses other than to make an Orbit, but I made this bundle so its easy for anyone to get a fixed position around an object. I also have example for Cos/Sine, Angle-To, Custom Ease, Bundle Library, and many many more on my profile JR 01.