2D Platformer Knockback

Discussion in 'Programming' started by ChrisMG12, Jan 13, 2018.

  1. ChrisMG12

    ChrisMG12 Member

    Joined:
    Jan 3, 2018
    Posts:
    75
    I'm using the code from this video,


    I tried searching all throughout the internet for a good tutorial for 2d platformer knockback, however the ones i could find allowed the player to move after being hit, or were for other genres of videogames,like topdown shooters.

    Could anyone please either provide me an explanation or a tutorial or a simple code for knockback such that the player doesnt get knocked back multiple times in a single period of time, and prevents usage of control while being knocked back.

    Thanks, any help would be appreciated, and sorry for the disturbance.
     
  2. TheouAegis

    TheouAegis Member

    Joined:
    Jul 3, 2016
    Posts:
    6,885
    Set a timer when the player gets hit. As long as that timer is counting down, the player can't be hit any more times.

    Method 1: When the player gets hit, also set a variable to true so the game knows the player was knocked back. In the player's control code, if that variable is true, exit the event.

    Method 2: Use a state machine where the knocked back state is distinct from all the others. Don't include control code inside the knocked back code.
     
  3. ChrisMG12

    ChrisMG12 Member

    Joined:
    Jan 3, 2018
    Posts:
    75
    i set up an alarm, however what should i write in
    if(not alarm[0])
    {

    }

    should i write something like place_meeting(x,y,obj_enemy)
    hit=true

    and if so what should i do for the character to move once he is hit
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice