_x += Math.cos(Math.atan2(ship._y-this._y, .ship._x-this._x)*-1)*5
_y -= Math.sin(Math.atan2(ship._y-this._y, ship._x-this._x)*-1)*5
Why did that work?
I thought you were supposed to use sin for x and cos for y...
Not complaining, just wondering.
EDIT: BTW it's using radians
Last edited by juststickman (2010-04-24 14:14:02)
Offline
I wish I could understand some of that.
Offline
So nobody knows?
Offline
My brain has a sad after looking at that D:
Offline
Comeon, where did all the people past algebra go?
Offline
Nobody.... That's just not right...
Offline
I don't know trigonometry
...but maybe scmb1 can help you
Offline
ThePCKid wrote:
I don't know trigonometry
![]()
...but maybe scmb1 can help you
Is scmb1 online?
Offline
If I could read that, I might be able to answer your question.
Offline
steppenwulf wrote:
My brain has a sad after looking at that D:
Ditto.

Offline
illusionist wrote:
If I could read that, I might be able to answer your question.
![]()
I'll get rid of anything to do with code and just leave the equation...
x = x + cos(atan2(sy2-y1, x2-x1)*-1)*5
y = y - sin(atan2(y2-y1, x2-x1)*-1)*5
Offline
juststickman wrote:
ThePCKid wrote:
I don't know trigonometry
![]()
...but maybe scmb1 can help youIs scmb1 online?
I am now. And, sorry, but I'm not getting anywhere with this.
I have a few questions: Are sy2, y1, y2, x1, and x2 all variables? What do they mean? What is the purpose of this equation?
Offline
I know someone who can help you. Dines. Ask him on his project. http://scratch.mit.edu/projects/Dines/999668
Or I can just ask him in real life.
Offline
Basically, it depends on the context.
Usually, you would use radians to find x using cosine and y using sine, in a perfect circle. Interesting, isn't it?
However, most likely in your context is something not related to a perfect circle.
What are you trying to do with those equations?
I forget what atan is, but I know tangent is the ratio between sine and cosine, maybe that reverses it.
Offline
Greatdane wrote:
Basically, it depends on the context.
Usually, you would use radians to find x using cosine and y using sine, in a perfect circle. Interesting, isn't it?
However, most likely in your context is something not related to a perfect circle.
What are you trying to do with those equations?
I forget what atan is, but I know tangent is the ratio between sine and cosine, maybe that reverses it.
here's a badly made ASCII diagram (ignore the .)
.....0<---[this is the player, x1 and y1 are its coordinates)..........
..................*<[this is an enemy, x2 and y2 are it's coordinates).
........................................................................................
I am trying to find how much x and y have to change to make the enemy move towards the player. My formula worked, but I don't know WHY it worked.
Offline
juststickman wrote:
illusionist wrote:
If I could read that, I might be able to answer your question.
![]()
I'll get rid of anything to do with code and just leave the equation...
x = x + cos(atan2(sy2-y1, x2-x1)*-1)*5
y = y - sin(atan2(y2-y1, x2-x1)*-1)*5
Okay, Let me explain this.
Cosine and Sine (Cos and Sin) are used for finding ratios of angles. If you have a 45 degree angle (Pi/4 Radians), they are the same. At 90 Degrees (Pi/2), Cos is 0, and sin is one. Usually one multiplies this by how far the object moved to find out how far it moved in the X direction and in the Y direction. You formula looks like this. The inside gives you the angle that the object is moving. Cosine finds the ratio of that angle (x:y)
and then you multiply it by 5, the amount it moved.
I hope that helped.
Offline
TheSaint wrote:
juststickman wrote:
illusionist wrote:
If I could read that, I might be able to answer your question.
![]()
I'll get rid of anything to do with code and just leave the equation...
x = x + cos(atan2(sy2-y1, x2-x1)*-1)*5
y = y - sin(atan2(y2-y1, x2-x1)*-1)*5Okay, Let me explain this.
![]()
Cosine and Sine (Cos and Sin) are used for finding ratios of angles. If you have a 45 degree angle (Pi/4 Radians), they are the same. At 90 Degrees (Pi/2), Cos is 0, and sin is one. Usually one multiplies this by how far the object moved to find out how far it moved in the X direction and in the Y direction. You formula looks like this. The inside gives you the angle that the object is moving. Cosine finds the ratio of that angle (x:y)
and then you multiply it by 5, the amount it moved.
I hope that helped.
That's about how far I could understand it
Offline
TheSaint wrote:
juststickman wrote:
illusionist wrote:
If I could read that, I might be able to answer your question.
![]()
I'll get rid of anything to do with code and just leave the equation...
x = x + cos(atan2(sy2-y1, x2-x1)*-1)*5
y = y - sin(atan2(y2-y1, x2-x1)*-1)*5Okay, Let me explain this.
![]()
Cosine and Sine (Cos and Sin) are used for finding ratios of angles. If you have a 45 degree angle (Pi/4 Radians), they are the same. At 90 Degrees (Pi/2), Cos is 0, and sin is one. Usually one multiplies this by how far the object moved to find out how far it moved in the X direction and in the Y direction. You formula looks like this. The inside gives you the angle that the object is moving. Cosine finds the ratio of that angle (x:y)
and then you multiply it by 5, the amount it moved.
I hope that helped.
Ok, that wasn't very helpful. My question was why did it work when I reversed the sin and cos.
I used sin for Y and cos for X and it worked. And no it was not 45°.
Offline
juststickman wrote:
Comeon, where did all the people past algebra go?
I'm halfway finished with trig, but my brain still haz a sad when I look at the equation xD
Offline
My questions make people's brains sad
Offline
juststickman wrote:
TheSaint wrote:
juststickman wrote:
I'll get rid of anything to do with code and just leave the equation...
x = x + cos(atan2(sy2-y1, x2-x1)*-1)*5
y = y - sin(atan2(y2-y1, x2-x1)*-1)*5Okay, Let me explain this.
![]()
Cosine and Sine (Cos and Sin) are used for finding ratios of angles. If you have a 45 degree angle (Pi/4 Radians), they are the same. At 90 Degrees (Pi/2), Cos is 0, and sin is one. Usually one multiplies this by how far the object moved to find out how far it moved in the X direction and in the Y direction. You formula looks like this. The inside gives you the angle that the object is moving. Cosine finds the ratio of that angle (x:y)
and then you multiply it by 5, the amount it moved.
I hope that helped.Ok, that wasn't very helpful. My question was why did it work when I reversed the sin and cos.
I used sin for Y and cos for X and it worked. And no it was not 45°.
Sin is Y and Cos is X.
Offline