SOLVED
Hi I have one problem and I have no idea how to solve it
When I rotate my sprite I want to move in direction where the sprite is pointed at.
Here is the code responsible for rotating and moving the sprite.
float char_dir = main_char.getRotation();
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Up) || sf::Keyboard::isKeyPressed(sf::Keyboard::W))
{
main_char.move(cos(char_dir * M_PI / 180) * 3, sin(main_char.getRotation() * M_PI / 180) * -3);
}
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Down) || sf::Keyboard::isKeyPressed(sf::Keyboard::S))
{
main_char.move(cos(char_dir * M_PI / 180) * -3, sin(main_char.getRotation()* M_PI / 180) * 3);
}
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Right) || sf::Keyboard::isKeyPressed(sf::Keyboard::D))
{
main_char.rotate(2.0f);
}
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Left) || sf::Keyboard::isKeyPressed(sf::Keyboard::A))
{
main_char.rotate(-2.0f);
}
It's not working properly.
I have no idea on how to move the character backward.
Moving forward is almost working properly. Almost
Also I did this because I read that it's important but it's still not working.
main_char.setOrigin(main_char_tex.getSize().x / 2, main_char_tex.getSize().y / 2);
Please help me.
Thanks.