More angular problems - Printable Version +- iDevGames Forums ( http://www.idevgames.com/forums)+-- Forum: Development Zone ( /forum-3.html)+--- Forum: Game Programming Fundamentals ( /forum-7.html)+--- Thread: More angular problems ( /thread-3214.html) |

More angular problems - Leroy - Jun 23, 2007 03:20 PM
Ok, I made this post on my previous thread and realized since I had been the last poster there for quite some time, that most people wouldn't bother to read it. Anyways, I'm still very confused about this. Here is the code I'm using(or at least its the basic idea) to move the player around, maybe someone could tell me what I'm doing wrong still. Oh, and everything is done in the upper right quadrant of opengl. float angle; float radians void move_player() { NSPoint vector; vector.x = new_world_dst.x - player.x; vector.y = new_world_dst.y - player.y; angle = atan2(vector.x, vector.y); radians = PI / 180 * angle; position.x -= sin(radians) * SPRITE_SPEED; position.y += cos(radians) * SPRITE_SPEED; } More angular problems - Tobs_ - Jun 23, 2007 04:13 PM
Does it throw an error or anything, or just a funny coord? Just checked my angle-finding code (azimuth or something?), and I used atan2(vectorY, vectorX); (swapped arguments around) Also, I added my cos value to position.y, and set normally had speed as negative (possibly had to do this because I swapped round the arguments for atan2) That's what worked for me, good luck in finding a solution =] Tobs More angular problems - Leroy - Jun 23, 2007 04:34 PM
Using the same code I posted originally the values(cast as ints) for angle I get using atan2 go as follow: NW through NE = 0 E = 1 SE = 2 S = 3 SW through W = -2 More angular problems - Leroy - Jun 23, 2007 08:27 PM
Anyone, please? More angular problems - Nevada - Jun 24, 2007 07:24 AM
Try, Code: `...` At least that's how it should work in the first quadrant.... More angular problems - Leroy - Jun 24, 2007 02:09 PM
Actually I figured out that atan2 returns in radians so, instead of using radians I use the angle: angle = atan2(vector.y, vector.x); position.x -= cos(angle) * SPRITE_SPEED; position.y += sin(angle) * SPRITE_SPEED; Seems to work fine now, thanks. |