Trig 101
ORBZ
Member Posts: 1,304
Just a little math tip for those that are interested:
You can think of circles and triangles and waves as all inter-related.
triangles can be used to draw circles by fixing a point in the middle and then rotating around the outside edge. In this way you can sort of say that trig is the study of the relationship between triangles and circles.
you can go around and around a circle always ending where you started.
you can similarly go up and down in a wave like motion always ending up where you started.
Now, there are a LOT of maths to learn about all the ins and outs of trig.
But one thing that I always found super useful is the incredible neat sin and cos functions.
with these functions you give them an input and they always return a value between -1 and 1. Neat huh? You can clip that to be just 0 and 1 if you wrap your trig function in the abs() function. It depends on your needs. Remember, 0 is another word for false, and generally speaking, NOT 0 is another word for true (i.e. 1) so we can create a simple flip-flop by just doing abs(sin(game.time)) this will oscillate between true and false at regular intervals. Neat huh? No timers. Additionally we get a fine grain of precision because of all the infinite values between 0 and 1.
This relationship has to do with circles and the nature of waves.
I'm not going to go deep into the maths behind it because i'm not an expert.
But whenever you are confronted with a situation where you would like something to smoothly move from point a to point b or oscillate between two states with a smooth "Wave like" or "Circular" motion you could try attacking your problem using the sin and cos functions.
Examples:
Platform moving back and forth smoothly
Object moving in a perfect circle
Repeatedly fading in and out smoothly
Repeatedly closing and opening something again.
Monsters attacking in a wave like pattern.
Basically, anything that has a repeating, circular, or wave like motion.
When plotting circles the sin function will give you Y, similarly the cos will give you X.
y will be the sin of the angle times the radius. x will be the cos of the angle times the radius.
When dealing with state flipping sin is usually used, but cos can be used instead for similar effect. cos is the wave right behind the sin wave. They are complementary to each other.
For more details I suggest Khan Academy on YouTube to learn all your math needs.
Note: Trig does NOT take TIME into account. For that, see calculus and physics.
Disclaimer: I'm not a math expert, but I have found this little bit of trig to be super useful.
Hope this helps someone
You can think of circles and triangles and waves as all inter-related.
triangles can be used to draw circles by fixing a point in the middle and then rotating around the outside edge. In this way you can sort of say that trig is the study of the relationship between triangles and circles.
you can go around and around a circle always ending where you started.
you can similarly go up and down in a wave like motion always ending up where you started.
Now, there are a LOT of maths to learn about all the ins and outs of trig.
But one thing that I always found super useful is the incredible neat sin and cos functions.
with these functions you give them an input and they always return a value between -1 and 1. Neat huh? You can clip that to be just 0 and 1 if you wrap your trig function in the abs() function. It depends on your needs. Remember, 0 is another word for false, and generally speaking, NOT 0 is another word for true (i.e. 1) so we can create a simple flip-flop by just doing abs(sin(game.time)) this will oscillate between true and false at regular intervals. Neat huh? No timers. Additionally we get a fine grain of precision because of all the infinite values between 0 and 1.
This relationship has to do with circles and the nature of waves.
I'm not going to go deep into the maths behind it because i'm not an expert.
But whenever you are confronted with a situation where you would like something to smoothly move from point a to point b or oscillate between two states with a smooth "Wave like" or "Circular" motion you could try attacking your problem using the sin and cos functions.
Examples:
Platform moving back and forth smoothly
Object moving in a perfect circle
Repeatedly fading in and out smoothly
Repeatedly closing and opening something again.
Monsters attacking in a wave like pattern.
Basically, anything that has a repeating, circular, or wave like motion.
When plotting circles the sin function will give you Y, similarly the cos will give you X.
y will be the sin of the angle times the radius. x will be the cos of the angle times the radius.
When dealing with state flipping sin is usually used, but cos can be used instead for similar effect. cos is the wave right behind the sin wave. They are complementary to each other.
For more details I suggest Khan Academy on YouTube to learn all your math needs.
Note: Trig does NOT take TIME into account. For that, see calculus and physics.
Disclaimer: I'm not a math expert, but I have found this little bit of trig to be super useful.
Hope this helps someone
Comments
Heh all I need is some cut-n-paste formulas for all the standard behaviors. I don't need to know how it works lol! But that's because I'm left-brain dead.
Thanks Orbz
Often it can reduce a set of complicated rules down into a single line of trig expressions.
This yields faster games and simpler code bases.
I hope it helps
I've found it to be useful myself. And no, i'm not a really good math person either. The concepts aren't that hard to understand once you get the hang of it. I highlighted the most useful functions sin and cos for me. Other functions like tangent are great for determining line-of-sight.
But don't worry, none of this stuff is required to use GS, it's just handy for doing some common tasks I see posted on the forums here.
The other nice thing about trig functions is that they give a "smooth" transition between states, so things slow down before stopping and reversing, etc.
try this:
put an actor on a scene, give it a Move behavior with the speed set to: sin(game.time * 100) * 100
Watch what happens. Now go figure out why
been using sin and cos, but been annoyed that i dont understand it.... this was a step in the right direction... so cheers
nan...
nothing like flatbread from tandoor!
http://gamesalad.com/forums/topic.php?id=4439
@ ORBZ
VERY GOOD TIP!!! KEEP THEM COMING!!! I will add that Cosine (cos) is the INVERSE of sin. When overlayed on top of each other...they look like a DNA helix in the movies...zig zagging at different rates back and forth (between -1 and 1) across their center axis...which is 0.
His point is that if you use a trig function in combination with a timer, you can create very smooth visual effects in your game.
My only criticism is that Trig and Constrained behaviors are resource intensive for GS at the present time. USE IN MODERATION AND VERY STRATEGICALLY!!!
I would recommend that if you need a trig function...set it up to run in a background math calculator actor (with any other complex math operations for use in the game). Then tap into the running oscillation at any time from any actor. Then have that actor reference the base sin wave motion value with any sort of magnifier or modification to the base sin wave value within the actor's unique expression. This will give you a running oscillation in the background to spread around throughout the game...rather than have the trig function in multiple actors. The trig function can also be within a game switch...which other actors can then turn on and off when they need a trig value (or any constrained math calculation for that matter).
@ the rest of you all
PAY ATTENTION IN CLASS....THIS IS VERY GOOD STUFF HERE!!! You don't have to be a math wiz to understand basic trig. It (combined with basic geometry...although they are really the same thing) can be very, very useful with game development.
http://gamesalad.com/game/play/47300
http://www.sidefx.com/docs/houdini9.1/ref/expression_cookbook
It's for another application but their write-up gives you some useful info and maybe some ideas.
Enjoy.
so much good info in here.