At 3/25/06 05:53 PM, -Vengeance- wrote: do you understand now?
A little bit more, thanks for helping. Let me know if I am right on my questions above though, to boost my confidence a bit bout t his stuff, I think I'm almost getting it... thanks
At 3/25/06 05:53 PM, -Vengeance- wrote: do you understand now?
A little bit more, thanks for helping. Let me know if I am right on my questions above though, to boost my confidence a bit bout t his stuff, I think I'm almost getting it... thanks
I got bored and wanted to make something cool in flash so I made this.
It's a nice visual aid to help people understand what Sine, cosine and tangent actualy are
(note it's flash 8)
Comments please :D
At 3/26/06 11:12 AM, Ninja-chicken wrote: I got bored and wanted to make something cool in flash so I made this.
It's a nice visual aid to help people understand what Sine, cosine and tangent actualy are
(note it's flash 8)
Comments please :D
http://img52.imagesh..hp?image=sine4fn.swf
lol youve got 360 in place of 270 on the slider (360 = 0) . Cool though
lol after all that fancy math I fuck up with a human error :P
My mistake here is a fixed version
At 3/26/06 11:21 AM, Ninja-chicken wrote: http://media.putfile.com/Trig-graphs
Nice :D
That would have helped me quite alot to understand sine and cosine a few months back, when I didn't have a clue what it was XD
Hmm, I don't get how that helps people though! I guess I'm just still confused about sin and cosine. I read this tutorial 3x now and I still don't understand it.....
My question is this
After reading this tutorial, how am I just supposed to know what to do with Math.sin and Math.cos and where I would put it in a game that I would script by myself? How would I know to say "Oh, well now I have to use Math.sin to get the magnitude of _y for some reason and Math.cos to get the magnatude of _x" That is what really confuses me... How do you know!?
Ahem, the question that I posted above is what I would really like answered most please!
I know I'm several months late answering your question, but in case you are still out there or anybody else has the same question I'll explain it as best I can. There is a little bit of intuition about when to use trig vs. other methods. One time when you will almost always want to use it is when you have some sort of magnitude and direction and you want to convert it into x and y components or vice versa.
If you have a magnitude and a direction you can get the x component by cos(angle)*magnitude and the y component by sin(angle)*magnitude.
If you have two components that you want to convert into a direction and a magnitude you can do atan(y/x) to find the direction and then magnitude is sqrt(x^2 + y^2).
Knowing when to bother converting back and forth can be trickier. It can give some games a different type of control. For example overhead racing games where the steering is fromt he cars point of view are based on this kind of idea. When you pess left and right the angle changes. You you press go the magnitude increases. The game stores that info and just converts it into x, y movement each frame.
Another time you want to use trig is when there is some value that you want to calculate each frame but don't know directly how to do it. When I come to a situation like this I find it useful to sketch the situation out. If you can find enough things that you already know about the situation and form a triangle with them, then you can use trig to find the piece of information that you want to know.
This kind of idea is used in this goofy little demonstration of circle collisions to prevent the little circle from penetrating the big circle. The idea of circle collision detection is that when the sum of their radii is greater than the distance between their centers there is a collision. Well, when there is a collision we want to know by how much so we can fix it. So if we sketch the situation out we can see that we can use the Pythagorean Theorem on the two blue sides to calculate the length of the dotted yellow line. We know the radii of the circles (green lines) because it's half of the width or height of the respective circle. So then we are able to calculate the length of the penetration amount (red line) by blue line + blue line - dotted yellow line. Or in other words the penetration amount is the difference between the sum of the radii and the distance between the centers of the circles. So once we know how much we want to move the circle we need to know which direction. This is easily calculateable from the two blue lines and atan. In the game I also used another little math trick so that both circles would be adjusted on a collision. Now I could have done each circle moved by half, but I was going to expand the game to have different sized target objects and wanted the big ones to be pushed slower so I used a ratio. You'll probably be able to figure out that part of the code by yourselves though. Anyway, the entire source code to the circle game thing:
onEnterFrame = function() {
//Update time left on the timer
time = Math.floor((60000 - getTimer()) / 1000);
//Calculate the distance between the centers of the solid circles
distance = Math.sqrt(Math.pow(circle2._x-circle1._x, 2)+Math.pow(circle2._y-circle1._y, 2));
//If there is a circle collision betweent he two solid circles
if (distance<circle1._width/2+circle2._width/
2) {
//Put circles back where the
angle = Math.atan2(circle2._y-circle1._y, circle2._x-circle1._x);
circle2._x -= Math.cos(angle)*(circle1._width/2+circle2.
_width/2-distance)*(circle2._width/2)/(cir
cle1._width/2+circle2._width/2);
circle2._y -= Math.sin(angle)*(circle1._width/2+circle2.
_width/2-distance)*(circle2._width/2)/(cir
cle1._width/2+circle2._width/2);
circle1._x -= Math.cos(angle)*(circle1._width/2+circle2.
_width/2-distance)*(circle1._width/2)/(cir
cle1._width/2+circle2._width/2);
circle1._y -= Math.sin(angle)*(circle1._width/2+circle2.
_width/2-distance)*(circle1._width/2)/(cir
cle1._width/2+circle2._width/2);
}
//Distance between the big circle and the ring
distance2 = Math.sqrt(Math.pow(circle1._x-circle3._x, 2)+Math.pow(circle1._y-circle3._y, 2));
//If the circle is entirely in the rignt increase the score and spawn a new target
if (distance2 < circle3._width/2 - circle1._width/2) {
score++;
newTarget();
}
//If the time is up end the game
if (time <= 0) {
delete _root.circle2.onEnterFrame;
delete _root.onEnterFrame;
time = 0;
}
};
score = 0;
//Make circles appear above the spawning ring
_root.circle1.swapDepths(1);
_root.circle2.swapDepths(2);
//Movement
_root.circle2.onEnterFrame = function() {
if (Key.isDown(37)) {
this._x -= 5;
}
if (Key.isDown(38)) {
this._y -= 5;
}
if (Key.isDown(39)) {
this._x += 5;
}
if (Key.isDown(40)) {
this._y += 5;
}
};
//Attach a new target and put it randomly on the screen
function newTarget() {
_root.attachMovie("Symbol 3", "circle3", 0);
circle3._x = random(Stage.width);
circle3._y = random(Stage.height);
}
newTarget();
A few final notes about my code. For those proficient with AS out there, YES, I realize I'm not using strict data typing or strict path referencing. Yes I know I could have defined a variable called radius to speed it up by not dividing by two each time and yes I know I could shorten the if statements for movement into two lines. However, for this demo I deemed those things umimportant and didn't do them so get over it. For people trying make the game make three movieclip objects name the small one circle1 the big one circle2. For the third one change its linkage to "Symbol 3".
So, like I said at the beginning, learning when to use trig can take some practice, but in this situation I hope you can start to see how a thought process in designing something like this would go. If this helped people I can do a few more things like this were I dig up my old codes and talk people through how I thought about the trig while writing it. If not, then at least I had fun for the last half hour.
Ok, but can you post an example of a "hand trig" from something like madness interactive or thing thing? (the raw code would also work : P)