So I've been reading various threads where people either have issues with or don't understand what the math operators do.
I decided I would compile all of the knowledge I have into a single thread.
In the future I intend for this thread to contain text and video tutorials regarding math in the track editor, but let's start small for now.
I read this post written by Blastergamer.
Here we go.Originally Posted by Blastergamer
One-Input Operators:
Abs:
Gives you the absolute of the input value.
A way to think of this is the number's distance away from zero.
So if you input 5 you will output 5, but if you input -5 you will still output 5.
It always removes the sign and returns a positive number.
Sign:
If the input value is zero, it will return 0.
If the input value is above zero, it will return 1.
If the input value is below zero, it will return -1.
Useful with a switch filter.
Sin(x) * 1000:
A trigonometric function.
Takes an angle as an input and outputs the sine of the angle times thousand.
In other words, it lets you know how much your object is pointing up or down.
A value of 1000 means it is pointing straight up and a value of -1000 means it is pointing straight down, a value of 0 means it is perfectly horizontal.
Cos(x) * 1000:
Same as as before, but outputs the cosine of the angle times thousand.
It let's you know how much you object is pointing left or right.
If you want to use sine and cosine, you'll have to use a set of these for each of the rotational axes if you're doing it in 3D.
You'll also have to work out what direction is what in the map in order to make sure you're assigning the right values.
Tan(x) * 1000:
Also a trigonometric function.
Returns the tangent of the input angle times thousand.
Imagine a right triangle where the straight sides represent X and Y coordinates on a flat space.
And the third diagonal side of the triangle (the hypotenuse) goes from the zero point, to the X and Y.
The angle that the hypotenuse is pointing at can tell us the ratio between the X and Y sides.
So the returned value is Y/X, which is why you get the value 1 at a 45 degree angle and infinity at 90 degrees.
In this case though the value is multiplied by a thousand before it is returned, so you get 1000 instead of 1.
ArcSin(x / 1000):
This is the inverse sine function, usually called arcsin or asin in most programming languages.
Instead of putting in an angle and receiving the sine of the angle times thousand, you put in the sine of an angle times thousand and receive the angle.
Keep in mind though that it can't figure out the angle of a full circle, only half a circle.
ArcCos(x / 1000):
Same as before, but takes the cosine as an input rather than the sine.
ArcTan(x / 1000):
The inverse of the tangent, also known as atan.
Takes the tangent of an angle times thousand as an input, and returns the angle.
Notice how infinity is required in order to output 90 or -90 degrees.
Again the resulting angle is within the range of two quadrants, or half a circle.
Log:
The logarithm of a number.
I suggest you look at this.
http://en.wikipedia.org/wiki/Logarithm
Let's say X is the input value and we use 2.718 as the base number of the logarithm; the equation is this:
X = 2.718 to the power of Y.
The logarithm of X is Y, so we get Y as an output.
If you input 20, you'd get 3 because it has to multiply the base number by the power of that amount (2.718 * 2.718 * 2.718 = 20..)
So the logarithm of 20 is 3.
You can use anything as a base number, but logarithms that use 2.718 are referred to as natural logarithms.
Why that number? I don't know, but it's a mathematical constant.
Have a look at these.
http://en.wikipedia.org/wiki/E_%28ma...al_constant%29
http://en.wikipedia.org/wiki/Natural_logarithm
Sqrt:
The square root of a number. Simple.
Not:
Inverts the input number so that anything positive becomes negative and anything negative become positive.
The important thing to note is that it does it in such a way where the input value cannot equal the output value, so 0 is not 0.
Round:
Rounds the number to the closest integer (whole number).
Floor:
Rounds the number down to an integer.
Ceil:
Rounds the number up to an integer.
Two-Input Operators:
Add, subtract, multiply and divide:
It's basic arithmetic, you should already know this.
Max:
Outputs only the bigger number of the two inputs.
Min:
Outputs only the smaller number of the two inputs.
Modulo:
Represented as mod or % in most programming languages.
I guess it's simple to explain what it does, but it's harder to explain why it's useful.
It's basically division.
It divides the first value by the second value, but you get the remainder of the division rather than the result.
If I divide 16 by 5 I get 3.2 (16 / 5 = 3.2).
But what if we are only allowed to divide whole numbers and not fractions?
We would only be able to divide by 4, and we would get a remainder of 1 (16 % 5 = 1).
Modulo is very useful for a number of reasons, like making a clock for instance!
Place a Two-Input operator and change its operation to Modulo, then change the second value to something like 10.
Now notice what happens with the output as you increase the first value and go beyond 10.
It resets to zero every ten increments!
This is very useful if you need a repeating number, this way you won't have to use a generic filter to see if a number has gone beyond a certain threshold and reset it with a set value event.
Pow:
Increases the first input value to the power of the second input value.
For example, 2 to the power of 3 (2^3 or 2*2*2) is 8.
Equals:
Outputs 0 if the first and second input values don't match each other.
Outputs 1 if they do.
It's like a generic filter, but rather than sending an impulse based on wether the condition is true or not it simply changes its output number.
Not Equals:
Same as before, but the inverse.
Greater:
Outputs 1 if the first input value is greater than the second input value.
Outputs 0 if it isn't.
Again, like a generic filter.
Less:
Same as before, but the inverse.
Greater Equals:
Same as the Greater operation, the difference is that this outputs 1 even when the first and second values are equal.
Less Equals:
Same as the Less operation, the difference is that this outputs 1 even when the first and second values are equal.
AND, OR and XOR:
If you want to know more about logic gates check out this video.Originally Posted by mutetus
http://www.youtube.com/watch?v=VBDoT8o4q00
Also check out this wikipedia article.
http://en.wikipedia.org/wiki/Bitwise_operation
ArcTan2:
If you haven't read about Tan or ArcTan in the One-Input Operators section, do so now.
This is also known as atan2 in most programming languages.
ArcTan2 is very useful, because it solves the issues you get with ArcTan.
Instead of inputting the tangent of an angle you input the horizontal and vertical coordinates (in reverse order).
It then outputs the correct angle for all four quadrants.
It is also more stable with numbers close to 0.
You would use this if you want an object to turn and face something.
Let's say the X and Y coordinates represent our playing field, and we have both a player ship and an enemy ship at any position.
We want the enemy ship to face the player's ship.
We first have to find what the player's position is in relation to the enemy's position.
We do this by subtracting the enemy's position from the player's position.
Player Position X - Enemy Position X = Offset X
Player Position Y - Enemy Position Y = Offset Y
We now have the offset values, these values are what the player's position would be if the enemy's position was considered the zero point in the coordinate system.
Let's input these into the ArcTan2 Operator.
Offset Y should be the first input value, Offset X should be the second.
The enemy's rotation can now be set to the output of the operator.
-----
I'm sure you people will let me know of all the things I got wrong and how I can improve this post.
I'll try to add cool video tutorials in the future on how to achieve certain things using the math operators in the track editor, but this will do for now.
If you have anything you'd like to add, I'll include it in this post.
Oh, you are soo kind!
Thanks![]()
And I'll try to explain these:
AND, OR and XOR in are logic operations to compare bits of the input numbers together. For example 1 AND 1 = 1 (both inputs must be 1 for the result to be true(1), 1 OR 0 = 1 (any input can be 1), and 1 XOR 1 = 0 (eXclusive or, any input can be true but not more than one at the same time).
E.G. 189 AND 68 = 4 because 189 in binary is 10111101, 68=01000100 and if you AND the bits in those numbers you'll get 00000100 which is 4.
Let's put these numbers in top of each other to see it better:
10111101
01000100
*********^
There are the only two numbers that are both 1 so the result is
00000100 which is (0*2^7)+(0*2^6)+(0*2^5)+(0*2^4)+(0*2^3)+(1*2^2)+(0 *2^1)+(0*2^0)=4
189 XOR 68 is
10111101
01000100
11111001=249 so the XOR in the editor works just like it should![]()
nice info
i was looking for some modulo tile before but i didn't know it was called modulo
Thank you for the info! I guess I'll have to read up a lot more on the subject.Originally Posted by mutetus
Added to the first post.
Nice thread! I wish you would have noticed my question in Barrys thread as well concerning 1 of the most important questions which im almost sure many people would like to understand. Creating the proper scoring so the score doesnt pass or go under the score bar? Including how to show scores when trying to use multipliers? I get so frustrated and cant think straight when math is involved. But thanks again for this thread!![]()
This is pretty simple. If you set the max score to say 1000, all you have to do is check if the score value has gone above 1000.Originally Posted by DeadEXit
You want a Generic Filter that is set to Greater Equals 1001 that pulls data from your score counter > On true goes to Set Value Event that sets the Score counter back to 1000. It could me more complex if you want to keep how much over the number went, but this is a simple way to keep the score within the limits of the score bar.
Can one of you fine gentlemen help me make a small code to compare three #? either = 3 or 0
aka I have 3 VDS, 1 or 0, I need to know if they equal 3 or equal 0. Both needs to give a positive on true impulse. Thanks in advance!
I was thinking selectors, or two input operators, but I need pretty small circuit.
I think the simplest way is to use the Min operator between the score and 1000. But of course if the data source MUST stay within range then filters are the way to go.Originally Posted by LukeMSki
Great thread, btw
Originally Posted by Jarr3tt88Do you need different impulse targets for when they equal 3 or 0? If not, then an n-input operator set to XOR might help. That should output a 0 when the data sources are all the same (either 1 or 0) and 1 when they are different.
Place an N-Input Operator and set it to Add, then select all three Variable Data Sources as operands for it.Originally Posted by Jarr3tt88
Place a Switch filter and select the N-Input Operator as the comparison value for it.
Set the case 1 value to 0 and the case 2 value to 3, then connect the case 1 and 2 impulses appropriately.
That works too.Originally Posted by xIronWarlordx