SFML community forums

Help => General => Topic started by: Pilly on April 01, 2018, 01:59:48 am

Title: Stun character
Post by: Pilly on April 01, 2018, 01:59:48 am
What would be the best way for me to have my character stunned for 3 seconds. I used a boolean Stunned. So if the character is stunned, keyboard inputs won't work.

if(Stunned == false)
   Player.playerMovement();

However, I can't seem to find a way to break out of the stunned once I make Stunned = true, nothing seems to work. I read up on the clock and time documentation but I still don't understand it.

I tried something like this.

Clock clock;
Time time;

clock.restart();
time = clock.getElaspedTime();
if (time.asSeconds() >= 3)
    Stunned = false;
Title: Re: Stun character
Post by: dabbertorres on April 01, 2018, 01:24:46 pm
Overall game clock?

if(!player.stunned)
{
    player.playerMovement();
    if(conditionToStun)
        player.stunTime = gameClock.getElapsedTime();
}
else if(gameClock.getElapsedTime() - player.stunTime >= sf::seconds(3.0))
    player.stunned = false;