Search Unity

For melee combat, do you script the hits or use triggers?

Discussion in 'Scripting' started by PhoenixRising1, Nov 25, 2015.

  1. PhoenixRising1

    PhoenixRising1

    Joined:
    Sep 12, 2015
    Posts:
    488
    I have been trying to convert my script based combat system to one with triggers instead but the results are not consistent, even though I'm using dynamic continuous detection on all objects. I don't expect the detection system to be unreliable so I'm probably doing something wrong, but if so, what? The thickness of the box collider for the sword is exaggerated just to make the detection better.

    To me it seems as if it makes no difference between using discrete and dynamic detection. I would love to hear your inputs.


    Edit: found a post about changing the fixed timesteps and maximum allowed timesteps, gonna play around with it and hopefully it will solve the wonky detection.
     
    Last edited: Nov 25, 2015
  2. Chom1czek

    Chom1czek

    Joined:
    Sep 19, 2015
    Posts:
    66
    Wouldn't it be easier and more efficient to just check Raycast and check how far are you from the target (attack range)? Even if you depend on physics you can then use Raycasthit result and addforce or whatever you need.
     
  3. PhoenixRising1

    PhoenixRising1

    Joined:
    Sep 12, 2015
    Posts:
    488
    I used raycasts before but if I use them I have to make the raycasts match the animations and if I make any changes to the animations I have to redo all the raycast calculations. Not sure what the best approach is, so I created a thread about it. So you use raycasts for combat then?
     
  4. Fajlworks

    Fajlworks

    Joined:
    Sep 8, 2014
    Posts:
    344
    Raycasting might do the trick for simple combat systems, but if he is making a combat system like Monster Hunter where you can attack different parts of bodies then I think collision detection is the way to go.

    @emphereallife, If you haven't read it already, this thread might give you some help:
    http://answers.unity3d.com/questions/174312/rpg-swing-attack-hit-detection.html

    Specifically, it mentions that collision detection approach might work if your animations are slow, like in Monster Hunter for example. If they are blitz fast, like 0.3 seconds, then raycasting could help.

    Sorry I can't give straight answers since I haven't tried such combat system myself. Best of luck!
     
    PhoenixRising1 likes this.
  5. Chom1czek

    Chom1czek

    Joined:
    Sep 19, 2015
    Posts:
    66
    I haven't started combat system in my project yet but Im almost sure I will use raycast thing :) I don't have complicated or troublesome animations so I should be fine :)

    @Fajlworks yes it will be good for simple combat system but there are few good solution in your link like OverlapSphere and such, I even think I will use it myself :)
     
  6. PhoenixRising1

    PhoenixRising1

    Joined:
    Sep 12, 2015
    Posts:
    488
    After reading a lot of topics (been researching this for hours) I managed to miss that one. The attack will take 1/3 to 1/2 of a sec depending on what type of attack it is, so maybe I'm better of using raycasts like I did before then. Thanks for reading :).
     
  7. PhoenixRising1

    PhoenixRising1

    Joined:
    Sep 12, 2015
    Posts:
    488
    I used either overlapshere or a raycast (depending on attack), and I think I will go back to that.
     
  8. LaneFox

    LaneFox

    Joined:
    Jun 29, 2011
    Posts:
    7,536
    I use Triggers, but fast stuff is not recognized.

    If its really fast, doing an overlapsphere or something will have to substitute for the trigger.
     
  9. PhoenixRising1

    PhoenixRising1

    Joined:
    Sep 12, 2015
    Posts:
    488
    Thank you for the replies guys. I have now reverted back to raycasts and learned a valuable lesson ;).
     
  10. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    I tend to use hit windows (time a hit can be registered), ranges and angles. These are always reliable... collisions won't be for thin vs thin unless you ramp up your fixed update to a silly rate.
     
    PhoenixRising1 likes this.
  11. Chom1czek

    Chom1czek

    Joined:
    Sep 19, 2015
    Posts:
    66
    Hit windows? What does it mean?
     
  12. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    Just a portion of time where collision is allowed.