• Create Account

Banner advertising on our site currently available from just \$5!

### #ActualEdvinas Kilbauskas

Posted 25 June 2013 - 04:26 AM

As I see no one is willing to give you straight forward answer. But I think I can answer to your first question, about angles and shooting.

This is how you do it:

sf::Vector2f mousePos = your mouse position vector;
sf::Vector2f shipPos = you ship position vector;
sf::Vector2f bulletVelocity();
sf::Vector2f bulletPosition();

float shotAngle = atan2(mousePos.y - shipPos.y, mousePos.x - shipPos.x);

bulletVelocity.x = cos(shotAngle);
bulletVelocity.y = sin(shotAngle);

bulletPosition.x += bulletVelocity.x;
bulletPosition.y += bulletVelocity.y;



This should get you started. I can't really tell more, because it would kill all the point of the programming in the first place - which is problem solving.

You should go google some vector math, get comfortable with those before you dig deeper into game programming.

### #1Edvinas Kilbauskas

Posted 25 June 2013 - 04:25 AM

As I see no one is willing to give you straight forward answer. But I think I can answer to your first question, about angles and shooting.

This is how you do it:

sf::Vector2f mousePos = your mouse position vector;
sf::Vector2f shipPos = you ship position vector;
sf::Vector2f bulletVelocity();
sf::Vector2f bulletPosition();

const double PI = 3.14159265359;

float shotAngle = atan2(mousePos.y - shipPos.y, mousePos.x - shipPos.x)*(PI/180.0f);

bulletVelocity.x = cos(shotAngle);
bulletVelocity.y = sin(shotAngle);

bulletPosition.x += bulletVelocity.x;
bulletPosition.y += bulletVelocity.y;



This should get you started. I can't really tell more, because it would kill all the point of the programming in the first place - which is problem solving.

You should go google some vector math, get comfortable with those before you dig deeper into game programming.

PARTNERS