Amerigo Moscaroli - Game Programmer
  • Home
  • University Projects
    • Eye-Snipe
    • Airport Mayhem
    • Star-Buck
    • HLSL Demos
  • Professional Work
    • Race Yourself - Glass (Beta)
    • Race Yourself - Mobile (Beta)
    • Race Yourself - Gear
    • Crazy Slots Adventure
    • Cops 'n' Robbers: World Tour
  • Tutorials
    • OpenGL ES Video Tutorials
    • Creating Cross Platform Games with Xamarin
    • Creating a 2D Platformer
    • Create and Monetize your C# Games on iOS and Android
  • Personal Projects
    • A Crack in Time - Dev Blog
    • Time Runner

Player Attacks Part 2

3/11/2019

0 Comments

 
Now that the animation is all set-up, the next thing I needed to implement was the attack state for the player. For my game, I'm currently going to have a combo system where the player can press the attack button multiple times to chain a melee attack. In the future, I might look at having different melee attacks such as strong attacks and special attacks, but for now I'll focus on the standard melee attacks.

First, I needed to add a new state class that the player can enter for attacking. I added multiple variables to this class:
  • The animation instance - used to trigger the attack animation montage
  • An int32 for the current combo count - this is to keep track of how many attacks the player has completed
  • An int32 for the maximum combo count - used to prevent too many attacks
  • A bool for whether or not a combo has been chained - this prevents spamming of the attack button
  • A bool for whether or not the player is in the "combo area" - this way, the player can only chain attacks between certain frames of the animation
I started overriding the OnEnter method from the IState interface - in this method I have reset the variables and told the animation to start the attack montage.
Next, I overrode the OnMessageReceived method, which is where the bulk of the logic will be as the state will handle messages from the animation - this method looks like the following:
Picture
In the OnAttackStart and OnAttackEnd, I will eventually activate the weapon however for now I have activated & deactivated the combo area. The OnAttackComplete message resets the playNextAttack boolean so that the player can trigger another combo attack. Finally, the OnAnimationComplete message will change the state to the Idle state.
Next I have overridden the the OnActionInputReceived method, where I check if the input is the Attack input, and if it is the player can attempt to combo an attack. The method looks like the following:
Picture
Finally, I overrode the OnExit method to stop the attack on the animation instance.

I had to create a subclass of the animation instance so I could add my own custom methods for performing the attacks. I added a variable for the animation montage of the attack, and 3 methods - StartAttack, ChangeAttack and StopAttack:
Picture
In the ChangeAttack method, I form the section names for the montage & tell the montage to set the next section. The StartAttack method simply starts the montage, and the StopAttack method stops the montage. Once this class was complete I re-parented the animation blueprint of the player to my new class.
The last step was to add the state to the PlayerController. Now, the player can attack:
Picture
In the next post I will discuss how I implemented the hitbox & the particle effect for the attack.
0 Comments



Leave a Reply.

    Author

    Software developer working on a game in Unreal Engine 4, this blog chronicles the development of the game.

    Archives

    March 2019
    February 2019

    Categories

    All

    RSS Feed