
GML provides the functions radtodeg() and degtorad() so we don’t really need to bother with knowing the math, but it’s good to know it.

If you want to manually convert from degrees to radians, use this formula:Īnd, to convert radians to degrees manually, it’s: Thus, if we want to feed our sine function a parameter value in degrees, we’ll actually need to convert it to radians, like this: Most people are used to thinking about trigonometry in degrees. Note: In GML, the trig functions take arguments in radians, while things like direction and image_angle are given in degrees. This can be very handy when trying to figure out math functions that will be useful in your game projects. Search for “graph ” and google’s search engine will give you an interactive graph that you can use to understand how functions behave. Note: Incidentally, the graphs in this article were generated by google.

Varying x slowly or quickly will influence the frequency of the oscillation.

Varying the position of an instance by such a small amount (we’re talking +/-1 pixel) would scarcely be noticeable, but we can just multiply this by a constant to increase the amplitude of the function, to suit our needs. The function y = sin(x) returns an oscillating value between -1 and 1. There are a number of interesting ways to apply the sin() function to motion. You just need to wrap your head around the math involved, which this tutorial will help with. The other downside is that for a lot of people, the math is harder to figure out than simply drawing out a brute-force animation. Try to avoid over-using calls to trig functions, because they are computationally more expensive than most math functions. The downside is that the math computation can get expensive if you have a lot of instances using it in the game. As well, the code for math-defined approaches takes much less memory, meaning your executable files will both be smaller and use less RAM. With math-defined motion, you have a great deal of flexibility, and you can adjust the behavior at runtime by varying the equation or the inputs. The downside is that it is time consuming to create animations, and they are not very flexible in terms of adjusting the motion procedurally. With an animation, you can get very precise positioning and motion, and at runtime it is cheap to play the animation compared to performing math functions. There are advantages and disadvantages to both approaches. Wave motion may be accomplished by “faking it” with a sprite animation, but it can also be easily created using trig functions.

Wave motion faked through animated sprite. Why arguing about Link’s gender is dumb, and why it’s important.“Null Room” hidden in Superman (Atari, 1979).video games, programming, the internet, and stuff
