Meteor 2 Scripting Functions
Math
int randomInt(int lower, int upper)
Generate a int between lower and upper (both inclusive).
print(randomInt(1, 10));
float randomFloat(float lower, float upper)
Generate a random float between lower and upper (both inclusive).
print(randomFloat(0, 1));
float randomDir()
Generate a random direction/angle.
print(randomDir());
Same as calling randomFloat(0, 360);
int/string randomArray(array inputArray)
Pick a random element from an array.
array<int> numbersArray = {1,1,1,2,3,4};
print(randomArray(numbersArray)); // 1 is most likely result
array<float> floatsArray = {1.0,1.1,1.2,1.3,1.4,1.5};
print(randomArray(floatsArray));
array<bool> boolsArray = {true,true,true,false}; // true is most likely
print(randomArray(boolsArray));
array<string> fruitArray = {"Apple", "Banana", "Orange", "Orange", "Orange"};
print(randomArray(fruitArray)); // orange is most likely result
array<vector2> vector2sArray = {vector2(1,1),vector2(1,2),vector2(1,3)};
print(randomArray(vector2sArray));
Supports int, float, bool, string and vector2 arrays.
vector2 getRotatedSize(vector2 size)
Get the bounds size of a rectangle rotated in degrees.
print(getRotatedSize(vector2(5,10), 90)); // 10, 5
vector2 rotatePoint(vector2 point, angle float, vector2 centrePivot)
Rotate a point around a pivot.
vector2 result = rotatePoint(vector2(0, 50), 270, vector2(50, 50));
print(result); // 50, 100
float pixelsToMetres(float pixels)
Convert pixels to metres.
print(pixelsToMetres(256)); // 16
16 pixels is 1 metre.
The alternate spelling "pixelsToMeters" can also be used.
A global constant PIXELS_PER_METRE (or PIXELS_PER_METER) is also available e.g. float met = pix / PIXELS_PER_METER;
float metresToPixels(float metres)
Convert metres to pixels.
print(metresToPixels(16)); // 256
16 pixels is 1 metre.
The alternate spelling "metersToPixels" can also be used.
A global constant PIXELS_PER_METRE (or PIXELS_PER_METER) is also available e.g. float pix = met * PIXELS_PER_METER;
float getBearingTo(vector2 fromPos, vector2 destPos)
Get the bearing from fromPos to toPos in the range 0-360.
float bear = getBearingTo(getPos(PLAYER_OBJECT), vector2(0,0));
print("Bearing to top left of map is: " + bear);
vector2 moveForwardOnBearing(vector2 pos, float bearing, float dist)
Move a position along bearing and return the result.
vector2 newPlayerPos = moveForwardOnBearing(getPos(PLAYER_OBJECT), getDir(PLAYER_OBJECT), metresToPixels(10));
setPos(PLAYER_OBJECT, newPlayerPos);
float getDistance(vector2 pos1, vector2 pos2)
Get the distance between 2 points in pixels.
print("Distance to top left of map is: " + getDistance(getPos(PLAYER_OBJECT), vector2(0,0)) + " pixels");
float getDistanceMetres(vector2 pos1, vector2 pos2)
Get the distance between 2 points in metres.
print("Distance to top left of map is: " + getDistanceMetres(getPos(PLAYER_OBJECT), vector2(0,0)) + "M");
The alternate spelling "getDistanceMeters" can also be used.
float clamp(float value, float minValue, float maxValue)
Clamp a number between two values.
print(clamp(-9999, 0, 100)); // 0
print(clamp(9999, 0, 100)); // 100
print(clamp(50, 0, 100)); // 50
Index
Generated on the 23 November 2024 at 08:20:42 (UK Time)