aiming and directional movement trouble in 2d game
Hi!
Im writing my second game now, and am having the same problems as i had on my first game.
When firing a bullet from a weapon i cant make it go in the exact direction i want it to go. On my last game (http://home.online.no/~stefjako) i made the bullet movements manually sort of. Very dirty. But now i use Math.cos and Math.sin to move it:
publicvoid draw(Graphics2D g2)
{
g2.setColor(Color.WHITE);
g2.drawOval(position.x, position.y, 1, 1);
}
/**
* Moves bullet!
*/
publicvoid move()
{
double newX = (double)position.x +Math.cos(angrad)*factor;
double newY = (double)position.y +Math.sin(angrad)*factor;
position.setLocation(newX, newY);
factor += speed;
}
Where angrad is the given angle in radians, factor = 1.0 , and speed = 0.1 by default.
This works kindof... But in certain angles the bullet will move straight in one direction for a while, and then suddenly start going in an angle. (sorry for the awful explaining)!
How do u guys usually make movements work nice and feel smooth?
Thanks!

