@Arcade,
I tried updating the rotation by small amount. It works correctly until it comes to 180 degree rotation.
Here is my function:
void Vehicle::move(float &rotation, int &c, sf::Vector2f &direction, sf::Vector2f ¤tVelocity, float &maxVelocity, float &acceleration, float &tempSpeed, int &increment, int &increment2, float &x, float &y, sf::Sprite &mySprite)
{
x += increment; //increment = 1
y += increment2; //increment2 = 0
mySprite.setOrigin(sf::Vector2f(mySprite.getGlobalBounds().width / 2, mySprite.getGlobalBounds().height / 2));
direction = sf::Vector2f(0.f, 0.f);
if((x >= 130 && x < 239*2 + 100) && (y >= 130 && y < 239*2 + 100))
{
rotation = mySprite.getRotation();
if(rotation > 0)
{
rotation -= 1;
cout << "rotation in first 0: " << rotation;
cout << endl;
mySprite.setRotation(rotation);
mySprite.move(10.f * tempSpeed / 1000, 0);
increment = 1;
increment2 = 0;
//Acceleration
direction.x = 1.f;
if(currentVelocity.x < maxVelocity)
currentVelocity.x += acceleration * direction.x * tempSpeed;
}
}
else if((x >= 239*2 + 100 && x < 239*4 + 100) && (y >= 130 && y < 239*2 + 100))
{
rotation = mySprite.getRotation();
if(rotation >= 0 && rotation < 90)
{
rotation += 1;
cout << "rotation in first 90: " << rotation;
cout << endl;
mySprite.setRotation(rotation);
mySprite.move(0, 10.f * tempSpeed / 1000);
increment = 0;
increment2 = 1;
//Acceleration
direction.y = 1.f;
if(currentVelocity.y < maxVelocity)
currentVelocity.y += acceleration * direction.y * tempSpeed;
}
}
else if((x >= 239*2 + 100 && x < 239*4 + 100) && (y >= 239*2 + 100 && y < 239*4 + 100))
{
rotation = mySprite.getRotation();
if(rotation > 0)
{
rotation -= 1;
cout << "rotation in second 0: " << rotation;
cout << endl;
mySprite.setRotation(rotation);
mySprite.move(10.f * tempSpeed / 1000, 0);
increment = 1;
increment2 = 0;
//Acceleration
direction.x = 1.f;
if(currentVelocity.x < maxVelocity)
currentVelocity.x += acceleration * direction.x * tempSpeed;
}
}
else if((x >= 239*4 + 100 && x < 239*5 + 100) && (y >= 239*2 + 100 && y < 239*4 + 100))
{
rotation = mySprite.getRotation();
if(rotation < 90)
{
rotation += 1;
cout << "rotation in second 90: " << rotation;
cout << endl;
mySprite.setRotation(rotation);
mySprite.move(0, 10.f * tempSpeed / 1000);
increment = 0;
increment2 = 1;
//Acceleration
direction.y = 1.f;
if(currentVelocity.y < maxVelocity)
currentVelocity.y += acceleration * direction.y * tempSpeed;
}
}
else if((x >= 239*4 + 100 && x < 239*5 + 100) && (y >= 239*4 + 100 && y < 239*5 + 100))
{
rotation = mySprite.getRotation();
if(rotation >= 90 && rotation < 180)
{
rotation += 1;
cout << "rotation in 180: " << rotation;
cout << endl;
mySprite.setRotation(rotation);
mySprite.move(10.f * -tempSpeed / 1000, 0);
increment = -1;
increment2 = 0;
//Acceleration
direction.x = -1.f;
if(currentVelocity.x > -maxVelocity)
currentVelocity.x += acceleration * direction.x * tempSpeed;
}
}
else if((x >= 130 && x < 239*2 + 100) && (y >= 239*4 + 100 && y < 239*5 + 100))
{
rotation = mySprite.getRotation();
if(rotation >= 180 && rotation < 270)
{
rotation += 1;
cout << "rotation in 270: " << rotation;
cout << endl;
mySprite.setRotation(rotation);
mySprite.move(0, 10.f * -tempSpeed / 1000);
increment = 0;
increment2 = -1;
//Acceleration
direction.y = -1.f;
if(currentVelocity.y > -maxVelocity)
currentVelocity.y += acceleration * direction.y * tempSpeed;
}
}
}
And, the output is:
https://imgur.com/CI1QrmVIt stops at 91 degree whilst it should increase up to 180 degree.
How can I increase the rotation up to 180 degree?