Welcome, Guest. Please login or register. Did you miss your activation email?

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - Tyrfing

Pages: [1]
1
General / Rotation 1.6
« on: April 08, 2013, 07:41:04 pm »
I am creating a tower defense game, I create the tower and the enemy and I want the tower to shoot at the enemy, I am rotating the bullet to face the enemy based on the position of the tower using this code right after creating the bullet

Bullets Temp;
Temp.SetX(TowerVector[a].GetX());
Temp.SetY(TowerVector[a].GetY());
BulletVector.push_back(Temp);

sf::Vector2f curPos = TowerVector[a].Sprite.GetPosition();
sf::Vector2f position =EnemyVector[b].Sprite.GetPosition();

const float PI = 3.14159265;

float dx = curPos.x - position.x;
float dy = curPos.y - position.y;

float rotation = (atan2(dy, dx)) * 180 / PI + 180;

BulletVector[BulletVector.size()].Sprite.SetRotation(rotation);
 
Its causes my game to break when it should shoot, is there anything wrong with the rotation code or is it something else?

Pages: [1]
anything