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

Author Topic: Stun character  (Read 992 times)

0 Members and 1 Guest are viewing this topic.

Pilly

  • Newbie
  • *
  • Posts: 2
    • View Profile
Stun character
« 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;

dabbertorres

  • Hero Member
  • *****
  • Posts: 506
    • View Profile
    • website/blog
Re: Stun character
« Reply #1 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;
 

 

anything