Hi all,
I have a gun, bullet and enemy.
The gun is rotated to the enemy correctly, the bullet is rotated from the guns rotation. If I draw a line from the bullet's position to the enemy's position it lines up perfectly. However when I move the bullet towards the enemy it 'drifts' away from its rotated position
bullet_x_pos = gun.getPosition().x;
bullet_y_pos = gun.getPosition().y;
gun.rotate(gun_angle); //gun angle is correct, lines up perfectly
bullet.rotate(gun_angle);
bullet.setPosition(bullet_x_pos, bullet_y_pos);//have reversed set position and rotate for bullet, same result
float bullet_velocity = 0.2;
//called everyframe- does not work as expected
void update_bullet()
{
bullet.move(cos(bullet.getRotation() * (3.14159265 / 180)) * bullet_velocity,
-sin(bullet.getRotation() * (3.14159265 / 180)) * bullet_velocity);
}
//second attempt, exact same result as first update_bullet() as above
void update_bullet()
{
bullet.move(-bullet_velocity,-bullet_velocity);//
}
I have attached two images one where the bullet(in blue) starts and where it ends, you can see it drifts off line.
I want the bullet to follow the red line.
All help appreciated