pighead10
|
  |
| Joined: 03 May 2009 |
| Total Posts: 10341 |
|
|
| 11 Apr 2012 11:10 AM |
| Say I have a thin projectile image facing upwards, and the direction it needs to go in it (0,1). I would want to rotate it 90 degrees. Is there an algorithm to work this out, so that it can be reusable rather than writing different sections for each object? |
|
|
| Report Abuse |
|
|
miloguy
|
  |
| Joined: 19 Dec 2009 |
| Total Posts: 7702 |
|
| |
|
su8
|
  |
| Joined: 06 Mar 2009 |
| Total Posts: 6334 |
|
|
| 11 Apr 2012 12:31 PM |
What do you think if the direction is 0,1 :P? I might have some formula let me search for it :PP |
|
|
| Report Abuse |
|
|
su8
|
  |
| Joined: 06 Mar 2009 |
| Total Posts: 6334 |
|
|
| 11 Apr 2012 12:33 PM |
Do you mean this?
Angle = Math.Atan2(DirectionX, -rocketDirectionY); |
|
|
| Report Abuse |
|
|
miloguy
|
  |
| Joined: 19 Dec 2009 |
| Total Posts: 7702 |
|
|
| 11 Apr 2012 12:35 PM |
or just
angle = math.atan2(direction.y,direction.x) |
|
|
| Report Abuse |
|
|
su8
|
  |
| Joined: 06 Mar 2009 |
| Total Posts: 6334 |
|
|
| 11 Apr 2012 12:35 PM |
Angle = Math.Atan2(DirectionX, -DirectionY)*
Uhh... I forgot to take the rocket out before direction.. That's straight from one tutorial :PP |
|
|
| Report Abuse |
|
|
miloguy
|
  |
| Joined: 19 Dec 2009 |
| Total Posts: 7702 |
|
|
| 11 Apr 2012 12:37 PM |
its better to keep a record of the direction as an angle then get the vector direction when you need it if you're doing something like a rocket. y before x in atan2 usually, that tutorial is weird (x, -y probably works though) |
|
|
| Report Abuse |
|
|
su8
|
  |
| Joined: 06 Mar 2009 |
| Total Posts: 6334 |
|
|
| 11 Apr 2012 12:41 PM |
| Well shouldn't it be in le alphabetic order? |
|
|
| Report Abuse |
|
|
pighead10
|
  |
| Joined: 03 May 2009 |
| Total Posts: 10341 |
|
|
| 11 Apr 2012 12:43 PM |
| Yes, it's 2D. atan2, seen it before but I don't know what it does... googling |
|
|
| Report Abuse |
|
|
| |
|
pighead10
|
  |
| Joined: 03 May 2009 |
| Total Posts: 10341 |
|
|
| 11 Apr 2012 12:56 PM |
| Don't know what an arc tangent is either ^^ |
|
|
| Report Abuse |
|
|
pighead10
|
  |
| Joined: 03 May 2009 |
| Total Posts: 10341 |
|
|
| 11 Apr 2012 01:01 PM |
"For any real number (e.g., floating point) arguments x and y not both equal to zero, atan2(y, x) is the angle in radians between the positive x-axis of a plane and the point given by the coordinates (x, y) on it"
i should get to know these functions a bit more |
|
|
| Report Abuse |
|
|
|
| 11 Apr 2012 02:12 PM |
you say it like I don't know what arc tangent is
of course I know what arc tangent is! you dare insult my knowledge of arc tangent?
it's.. uh.. the.. uh.. arc of a tangent? |
|
|
| Report Abuse |
|
|
Oysi
|
  |
| Joined: 06 Jul 2009 |
| Total Posts: 9058 |
|
| |
|
miloguy
|
  |
| Joined: 19 Dec 2009 |
| Total Posts: 7702 |
|
|
| 11 Apr 2012 06:53 PM |
the only trig (maybe a little more for rare cases) you need to know for 2D game developement is
vector(cos(angle),sin(angle)) = angle to unit vector
atan2(vector.y,vector.x) = unit vector to angle
sqrt(squared(a.x-b.x)+squared(a.y-b.y)) = distance between points a and b
(degrees/180)*pi = degrees to radians (radians/pi)*180 = radians to degrees |
|
|
| Report Abuse |
|
|
pighead10
|
  |
| Joined: 03 May 2009 |
| Total Posts: 10341 |
|
|
| 11 Apr 2012 07:07 PM |
| The irritating thing is I like to be able to manipulate this stuff - I know almost all of the maths for this kind of thing except for trig functions like cos and sin, because I have absolutely no idea what they are :( |
|
|
| Report Abuse |
|
|
ZackZak
|
  |
| Joined: 26 Jul 2009 |
| Total Posts: 2811 |
|
|
| 11 Apr 2012 07:19 PM |
| Use atan2(y, x) to convert to an angle, then offset the angle and covert it back into a vector with (math.cos(x), math.sin(y)). |
|
|
| Report Abuse |
|
|