More angular problems
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;
}
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;
}
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
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
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
NW through NE = 0
E = 1
SE = 2
S = 3
SW through W = -2
Anyone, please?
Try,
At least that's how it should work in the first quadrant....
Code:
...
angle = atan2([b]vector.y, vector.x[/b]);
...
position.x [b]+= cos[/b](radians) * SPRITE_SPEED;
position.y += [b]sin[/b](radians) * SPRITE_SPEED;
...
At least that's how it should work in the first quadrant....
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.
angle = atan2(vector.y, vector.x);
position.x -= cos(angle) * SPRITE_SPEED;
position.y += sin(angle) * SPRITE_SPEED;
Seems to work fine now, thanks.
Possibly Related Threads...
Thread: | Author | Replies: | Views: | Last Post | |
Combining then splitting angular and linear velocity | reubert | 4 | 6,836 |
Sep 5, 2006 12:47 AM Last Post: reubert |