Math for the Algebraically Challenged

Started by aokmaniac13, November 20, 2005, 04:19:10 PM

Previous topic - Next topic

aokmaniac13

Okay I'm starting this thread as a "demonstration" of math operations to help total newbs manipulate variables in mugen.  In this case, time is the only variable.  I will post some of the basics and everyone else can add on to it. (I have supplied pictures for this tutorial, if you do not provide one I can make it for you.)

To start, here we have a set of Axes.  The origin is at the left-center, 0,0.

For all extents and purposes, we will assume the X axis represents Time.  Throughout this demonstration we will be manipulating time, which is why the graph does not include negative numbers in the X direction.
First we have constants. Constants are just unchanging numbers, like 10 and 20.  Here we have Y= 0, Y=10, and Y = 20

Notice they do not change due to time.  This is because time is not included in the expression.  However if we plotted Y = Time

You can see that Time is equal to itself, for obvious reasons.  We can shift this plot in many ways such as the four basic operations, addition,subtraction,multiplication, and division.

Using addition, you can set where the graph starts from, useful for possibly an attack that increases in damage the longer you charge it (Charging it for 0 time will still produce some damage)
Using multiplication or division, you can make that same attack charge faster or slower without having to change the laws of physics and cause time to go faster or slower.
Now we get more complicated.  Suppose the attack mentioned earlier was charging too slowly for you, but time*1000 is way too broken.  You can use an exponent for this.

Time^2 is just another notation for Time*Time. The bigger the exponent, the faster the graph curves upward.  And just as the inverse of multiplication is division, the inverse of an exponent is a logarithm.

I think you get the idea.
However by far the most useful operation is the modulus.  Modulus is like division, but instead returns the remainder of the operation, not the quotient.

I have also graphed y=10 to show that the graph never goes to ten, because the remainder of any multiple of ten divided by ten is always zero.  This is great for times when you want to do something every X ticks.  Lastly, we have trigonometric functions.  For now I will only demonstrate the sine curve.

This is a bit complicated, so I'll go into detail about the expression first.
20*sin((pi/12)*time)
Normally a sin function goes from 1 to -1, so I multiplied it by 20 to make the range 20 to -20.  Then on the inside, I multiplied time by PI and then divided by twelve.  The period (or how long it takes for the sine curve to repeat) is usually 2*PI, which is around 6.28, not a very clean number if you ask me.  The period of my equation is 24, so it repeats whenever time is a multiple of 24.  Why?  Because 2*PI/(PI/12) = 24 :) If I multiplied time by PI/6 instead, my period would be 2*PI/(PI/6) = 12  You can use the sin curve for all kinds of things, but it's main usage comes from palette effects, such getting hit by fire.  The player should gradually go from normal to red and back again.

If any of this is too confusing/could be explained better let me know.
One last note: In mugen, it doesn't hurt to add .0 to every number to make sure mugen doesn't truncate anything (cut off the decimals).

Renzo F

...and it doesn't hurt to truncate an expression with ceil() or floor() to avoid that nice debug warning messages...

Nice tutorial. Basic stuff that any creator should know (and should learnt at school).

外音リザ

To save on SFF space and added flexibility, any explod that revolves or moves around the character should be programmed with algebraic expressions instead of absolute positioning from sprites.
Orochi Herman: MUGEN Creator, Producer Video Editor and Web Programmer

And possibly more other shady things lol

https://www.facebook.com/OrochiHerman/

Foxphoenix

Quote(and should learnt at school).

This was too advanced for a puertorican school at my age so I could never learn most of this stuff.

????

FEh.. too easy...  :D

sup Mugen coding class 101  :P
Goodbye V ^_^ V

Foxphoenix

#5
Quote from: Lord Yagami on November 22, 2005, 01:22:52 AM
FEh.. too easy...  :D

sup Mugen coding class 101  :P

Well. It's stated in the topic title. "Math for the Algebraically Challenged" Not everyone could learn this stuff or is good enough for it. And I apply for both things  :P

@Jazzy. If you have more stuff to add here. I'm all ears ...errr eyes!  --;

Parker

It was good if somebody translate the tutorial to spanish... :sugoi:

Chosen_01

Meh. You lost me at "20*sin((pi/12)*time)" Was never a math wiz. If I could learn this it would be a friggin miricle. -_-

Mário Fong

#8
it means "20 multiplified by sin[that cool and useless thing that you learn in the 8th grade]((pi divided by 12)* teh time)" what's so hard???

Cybaster

What's so hard is that not everybody is good at maths or had the chance to be able to learn this at school.

And, understanding the formula as you did isn't the most complicated part. The complicated part is to understand what it's meant for, and what effect or purpose it will finally give.

????

ARe these for how the way the character moves in mugen?

I would like to know..  :-\
Goodbye V ^_^ V

Byakko

That's for anything mathematical. If you want to give a mathematical move to your char (a sinusoidal projectile for example), you have that.
If I struggled to the end of my determination, to the end of my way of life with my followers, if the result is ruin, then this ruin is inevitable. Grieve. Shed tears. But you cannot regret.

Mr. Sand

Quote from: Alice Margatroid on November 21, 2005, 08:11:12 AM
To save on SFF space and added flexibility, any explod that revolves or moves around the character should be programmed with algebraic expressions instead of absolute positioning from sprites.

Ahhhhh What?

Renzo F

Take Strider Hiryu's Uroboros as an example.
In that move, two projectiles move around Hiryu. Instead of adding a lot of sprites with the projectiles positioned in different angles, you can just use some math and one sprite.

The first Hiryu I downloaded was programmed not using math, and the Uroboros looked and played like crap :(

#Shaun

#Shaun never took trig.  ;P
#Shaun never took calculus :P
#Shaun barely passed Algebra. :ninja:

After finding this topic, #Shaun will now have a better understanding of what type = projectile, trigger = time % 60, offset = 10 + ( floor(time/60) * 20 ), 0 means. Thanks!

conicteam


ultimatedude


No Borders, No Nations

Ryanide

I'm still having trouble understanding this. I'm a visual learner, so could you maybe give some examples of these in actual Mugen code? I'm interested in learning this so I can make my characters main projectiles (floating fire) move at angles and sines without having to rely on sprite positioning.
A magical force-field surrounding a brick in an iron vault...even if the security is breached, the thieves are bound to be disappointed.

DMK

Lol, I remember reading this and wondering what in the flying fuck you were going on about.

Now that I know what the axis and all that stands for it's like looking at a small tutorial.  :D

aokmaniac13

Given the amount of interest, I will be expanding this further in the near future.

Quote from: Ryanide on November 09, 2007, 08:54:00 AM
I'm a visual learner, so could you maybe give some examples of these in actual Mugen code?
Ask and ye shall receive.