samspade
Member
I'm working on translating my current vector scripts from 2.2 to 2.3. The basics seem to be working, but I'm not very experienced with the new functions and methods. So if anyone with more experience has a moment to look this over and let me know if it looks right, and is the proper way to do it now, I'd appreciate it.
Everything below is located in a script file.
Everything below is located in a script file.
GML:
function vector(_x, _y) constructor {
x = _x;
y = _y;
static set = function(_x, _y) {
x = 0;
y = 0;
}
static add = function(_other) {
x += _other.x;
y += _other.y;
}
static subtract = function(_other) {
x -= _other.x;
y -= _other.y;
}
static multiply = function(_scalar) {
x *= _scalar;
y *= _scalar;
}
static normalize = function() {
if ((x != 0) || (y != 0)) {
var _factor = 1/sqrt((x * x) + (y *y));
x = _factor * x;
y = _factor * y;
}
}
static set_magnitude = function(_scalar) {
normalize();
multiply(_scalar);
}
static limit = function(_limit) {
if (point_distance(0, 0, x, y) > _limit) {
set_magnitude(_limit);
}
}
}
Last edited: