Interactive demo. Mouseover to activate, drag planets around.
This is an example of making an instance orbit around other instance in GameMaker.
In contrast to other similar examples (and commonly given advice of the kind), it allows to define orbiting speed in a common way (pixels/frame instead of degrees/frame).
This is accomplished by calculating the distance to orbit' center (from current position), calculating the orbit' length, and thus converting pixel speed to degree speed.
New position is then calculated and instance' speed is adjusted for it to reach it the next frame.
This allows to use direction in collision calculations as per usual.
Overall, the code is simple enough but documented regardless.
Code follows,
Continue reading