Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

How to start with a Simple physics based melee system?

Discussion in 'Scripting' started by PerpetualCringe, Aug 27, 2020.

  1. PerpetualCringe

    PerpetualCringe

    Joined:
    Aug 27, 2020
    Posts:
    5
    I have no found good ways to go about making good melee system on both unreal and unity. So I wanted to check here if anyone could give a good answer or point me to a good video. I'm trying to parrot Dark Messiah's combat when I say physic based combat, because I can't get over how much fun it is. I guess another good example is dying light's melee combat, but that's a bit of a far stretch of what I am really looking for. Either way I'm just trying to make a combat system like Dark Messiah in a new engine. Or at least a very rough prototype of one.
     
  2. PerpetualCringe

    PerpetualCringe

    Joined:
    Aug 27, 2020
    Posts:
    5
    idk actually if im supposed to post here then i posted in the answers section but idk how that works either
     
  3. PraetorBlue

    PraetorBlue

    Joined:
    Dec 13, 2012
    Posts:
    7,722
    I looked up Dark Messiah. The combat seems to just be your standard hitbox-based stuff, but a lot of the attacks apply physics impulses to affected enemies. That's probably all there is to it - just AddForce with ForceMode.Impulse in Unity would do the trick when you hit an enemy. Lots of ragdolling too
     
  4. PerpetualCringe

    PerpetualCringe

    Joined:
    Aug 27, 2020
    Posts:
    5
    The thing is I don't know where to start to begin adding melee into the game, im usually an unreal engine person. So i dont know a lot about unity programming. I also have some ideas to make it a bit different from dark messiah. But i want just the melee combat in the game first.
     
  5. PerpetualCringe

    PerpetualCringe

    Joined:
    Aug 27, 2020
    Posts:
    5
    thats good that its not too complicated
     
  6. PraetorBlue

    PraetorBlue

    Joined:
    Dec 13, 2012
    Posts:
    7,722
    I'd start first with using either a short range
    Physics.BoxCast
    or CapsuleCast. Hook that up to a simple input such as
    Input.GetKeyDown(KeyCode.Space)
    and see if you can get it to properly detect enemies in range of your character. Then you can apply whatever damage effects/knockbacks/etc.

    Then when you have that working you could try introducing animations. When you have an appropriate attack animation, pick a suitable frame in the animation to be the "hit" frame, and add an Animation Event there: https://docs.unity3d.com/Manual/script-AnimationWindowEvent.html

    Then start doing your boxcast from before in response to that animation event instead of the basic input from before.
     
  7. Zer0Cool

    Zer0Cool

    Joined:
    Oct 24, 2014
    Posts:
    203
    I would start with good implemented physic based 3rd (or 1st) person character controller and then build ontop of this the melee combat system.A good controller alone costs a lot of time for development. In my opinion it makes not much sense to develop the melee combat system without a working character controller. Most of the melee attacks are based on the controller, the used animations, animations states and the camera movement. At a second step i would add additionally behaviors for different (physical) attacks and physical reactions for the corresponding AI game opponents (that uses this controller too)