My camera movment works, however, if I hold the the 'S' key (down) it will move the camera down as i want to, but then if I hold 'W' after holding 'S' it will always go up. I tried many ways to fix this, all were not working and just confusing. Can you guys help me improve this code?
extern float deltaTime;
int hor = 0;
int ver = 0;
if (sf::Keyboard::isKeyPressed(sf::Keyboard::W))
{
ver = 1;
}
else if (sf::Keyboard::isKeyPressed(sf::Keyboard::S))
{
ver = -1;
}
if (sf::Keyboard::isKeyPressed(sf::Keyboard::A))
{
hor = -1;
}
else if (sf::Keyboard::isKeyPressed(sf::Keyboard::D))
{
hor = 1;
}
if (hor != 0 || ver != 0)
view.move(speed * hor * deltaTime, speed * -ver * deltaTime);
//y value is inverted, camera works with +y being down and -y being up
hor is a number to store the direction in the horizontal axis.
ver is a number to store the direction in the vertical axis.