-
Notifications
You must be signed in to change notification settings - Fork 0
Tutorial : Random Vectors
#Tutorial 03 : Random Vectors
RUL is designed for use in game development, so vector-randomization is one of its core features.
All functions related to vector-randomization are located in the
RUL.RulVec
class.
RUL provides many ways to generate random vectors. In this tutorial I will showcase just a few of them.
Note that function names and parameter types may differ slightly, depending on which framework or engine you are using. Most of these functions are also available for 3-dimensional vectors.
###RulVec.RandVec2(float lowerBoundX, float lowerBoundY, float upperBoundX, float upperBoundY) This is the easiest way to generate a random vector. The parameters create a rectangle that will contain the random vector.
for(int i = 0; i < 100;i++)
Vec2 myVector = RUlVec.RandVec2(200,200,400,400);
###RulVec.RandVec2Between(Vec2 pointA, Vec2 pointB) Another simple function. This will create a vector that lies somewhere between pointA and pointB
for(int i = 0; i < 10;i++)
Vec2 myVector = RulVec.RandVec2Between(new Vec2(200,200), new Vec2(400,400))
###RulVec.RandVec2(Vec2 baseVector, float maxAngle) This one is a little more complicated, but quite useful. This function takes a base vector and an angle(in radians). The output is a copy of the base vector that will be randomly rotated by an angle between -maxAngle and maxAngle.
for(int i = 0; i < 20; i++)
Vec2 myVector = RulVec.RandVec2(new Vec2(300,200),(float)(Math.PI / 2F));//maximum angle of 0.5 Pi (90°)
For more ways to randomize vectors, check out the documentation