HI
I have a player that moves in a circle. I used sf::transform and rotate which takes in the angle in degrees and the center to rotate about. I want to fire bullets from this circle to the center. The center point is predefined.
How do I go about doing this? I am trying to use vector maths but it is not working out. It moves but not to the correct location.
And also how do I map the bullet to the player each time the player shoots?
I've added some of my code for reference.
void Player::turn(){
float angle = 0.5;
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Right)){
transform.rotate(angle, {1920/2.f, 1080/2.f });
}
}
void Shoot::update(sf::RenderWindow& window){
float bulletX = _bullet.getPosition().x;
float bulletY = _bullet.getPosition().y;
float disX = _center.getPosition().x - bulletX;
float disY = _center.getPosition().y - bulletY;
float shot_RotationAngle = (atan2(disX, disY));
_bullet.setRotation( (shot_RotationAngle * 180 / 3.14159265) );
// Distance formula
float length= sqrt(disX*disX + disY*disY);
float newX = disX;
float newX = disY;
// Normalize the value
newX/= length;
newX/= length;
bulletX += ((newX*0.1));
bulletY += ((newX*0.1));
_bullet.setPosition(bulletX, bulletY);
}