I am making a basic "space shooter" game to test myself. I am using SDL external library in c++ to make it. I have a class called "Bullet" and a vector of Bullet objects. I als o have a class called "Ship", which is the player. When the player shoots, one of the Bullet objects is teleported to the player and given the angle of the player. The problem is that when the player is to the side the bullet is off-center. Can anybody help me? Here is my code for my class:
void Bullet::shoot(float ship_x, float ship_y, float ship_angle, int ship_width){
x = ship_x + (ship_width/2) - (width/2);
y = ship_y;
angle = ship_angle;
}
When the ship is pointing up (0 degree angle) or down (180 degree angle) than the bullet spawns perfectly. But the more away it gets from those the more off kilter it gets. Any thought?