The and for Vectors
Note
This ramble is exclusive to GameMaker Studio. I'd recommend doing your own research before applying any of this to any other project.
If you've ever seen or used another game engine, such as Godot, You may have noticed that GameMaker Studio lacks the familiar vector type.
In most cases, this is fine. Objects provide x and y variables for their positions anyway.
HOWEVER!
If you find yourself doing something more complex, such as making your game's UI reactive. Where the positions of different elements change quite a lot. You might miss them.
Creating your own makeshift vectors can be done a number of ways in GameMaker Studio.
Examples
| Method | Rating |
|---|---|
| Arrays | |
| Structs | |
| Constructor |
Warning
There is a lot you can do to get close to a proper vector system in GameMaker Studio. However, it will never be perfect due to the engine's limitations.
All three of these methods will work just fine for any of your projects, but constructors are closers to what you'd find in Godot. Constructors also have their own type that can be used in documentation. (See Documenting Your Code)
Structs and Constructors also allow you to include functions, like we just did for Vec2().magnitude().
Personally, I prefer using Constructors, but it's up to you what you decide to use.
Remember that there isn't anything wrong with just using a few well named variables.
Objects still use separate x and y variables, so it's a good idea to follow that when doing player position, for example.