Search Unity

Implementing melee attacks that do damage south of your character?

Discussion in 'Game Design' started by makewebsocketsgreatagain92, Jan 12, 2020.

  1. makewebsocketsgreatagain92


    Jan 8, 2018
    I have a collision shape that is basically the weapon. When a character swings, it's very smooth and the knockback effect / destroying objects is responsive. However, when a crate or monster is below the character, how can I make the character swing south so it looks correct?

    I'm bad at explaining things, so I made an example:

    I know in Chronicon, the character swings either left or right, and "x/slash" marks are shown. But in a non-pixelated game, it just looks soo out of place, hard to explain.

    Any advice is greatly appreciated.
  2. makewebsocketsgreatagain92


    Jan 8, 2018
    Looks I can fiddle around with the animation system and just make the sword swing below the character. Move the arms a bit to give it a bit more range. Just looks so funny lol
  3. Murgilod


    Nov 12, 2013
    The simple answer is: don't.

    By making it so that the player can't do 360º attacks, they have to be more aware of their positioning in the scene, which adds an extra level to the gameplay.
  4. Serinx


    Mar 31, 2014
    Can you add another attack animation which stomps downward? or just automatically damage enemies that you land on?

    Without some context of how the levels and enemies are positioned that might not make sense.
    angrypenguin likes this.
  5. SparrowsNest


    Apr 6, 2017
    Do you have just one attack that does a huge sweep?

    Think about making directional attacks, like a front jab(just forward), a side slash (left/right a forward), stuff like that.
    also what @Murgilod said should be considered, adds more tactical play into play.

    if you tell us more about the game we can offer more solutions.
  6. newjerseyrunner


    Jul 20, 2017
    How good is your programming ability? The game I'm working on is largely a third person shooter, however, I do have two melee weapons, as well as being able to strike enemies with the butt of the gun. I came across the same situation and solved it with about a hundred lines of code. I broke the swing down to three parts: the wind up, the attack, and the follow-through.

    The wind up: When the melee button is pressed, I do a spherecast to get all enemies within range. I then eliminate the ones behind me, then chose the closest remaining enemy. I ask the enemy's script for the Transform of it's head, then store that as the actual target. Then I take the current difference between the tip of the sword and the target and do some math to find a new point that will increase this distance, while staying within a certain rotation from the player. Then I Lerp the sword to this position over the next fraction of a second. This makes the attack always different and look nicer in my opinion. If the enemy is to the player's left, you'll see your character wind up by moving his sword to the right, to get a bigger swing. If your enemy is below you, your character will bring his sword up like he's about to chop down, and if the enemy is above you, you'll lower the sword to make a big upswing.

    The attack: The easiest part of the animation, just Lerp towards the target, accelerating as you go.

    The follow-through. Once the weapon has made it's impact, I do some math based on the original wind up point and the current position of the sword, the doubling it, and doing some rotational math to find a new point. Then Lerping to that while decelerating.

    I find that this technique makes my animations extremely smooth and looks way more complex than it is. Every slash or stab is different and you never get the case where a stock animation clearly misses the target, but you damage them anyway.