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

Good ways to deal with high speed melee animations

Discussion in 'General Discussion' started by MaximumTre, Oct 13, 2019.

  1. MaximumTre

    MaximumTre

    Joined:
    Nov 28, 2015
    Posts:
    163
    Hello.

    So I want to allow my players to have a "Haste" ability where they can speed up their movements etc, like many games do, but I was wondering if anyone had a good way to handle these types of high speed collision checks. So far, I thought about adding extra colliders or just making the collider really big, but that doesn't work too well in some situations. Next I tried doing a OverlapSphere/Box at the hit point, but it's not consistent. Any insight would be greatly appreciated. I wonder how games such as Warframe and the DMC series do this because some of the attacks can be pretty fast.

    This is for a third person game. Pretty sure that was obvious but I put it here for the sake of being clear :)
     
  2. Antypodish

    Antypodish

    Joined:
    Apr 29, 2014
    Posts:
    10,579
    The easiest way, start timer after executing hit and then check if target is in range. You don't need really fast collision detection. You could also use raycast, when executing hit.
     
    Last edited: Nov 16, 2020
    MaximumTre likes this.
  3. Murgilod

    Murgilod

    Joined:
    Nov 12, 2013
    Posts:
    9,753
    Box, Ray, Sphere, and CapsuleCasts are going to be your best friend.

    https://docs.unity3d.com/ScriptReference/Physics.BoxCast.html
    https://docs.unity3d.com/ScriptReference/Physics.Raycast.html
    https://docs.unity3d.com/ScriptReference/Physics.SphereCast.html
    https://docs.unity3d.com/ScriptReference/Physics.CapsuleCast.html
     
    angrypenguin and Ryiah like this.
  4. MaximumTre

    MaximumTre

    Joined:
    Nov 28, 2015
    Posts:
    163
    Yeah, I know how to use the different casts, and those do work great in other situations. I feel very slow for not realizing I could just check the range instead of using a collider.
     
  5. DoctorShinobi

    DoctorShinobi

    Joined:
    Oct 5, 2012
    Posts:
    219
    How about using Continuous Speculative on your character's rigidbody? I think Unity added this mode for the type of collision that involves high speed rotation(like a sword swing).

    upload_2019-10-14_0-29-44.png
     
  6. Reekin

    Reekin

    Joined:
    Oct 7, 2015
    Posts:
    10
    I've tried this method, but it doesn't work, melee still miss.
     
  7. neginfinity

    neginfinity

    Joined:
    Jan 27, 2013
    Posts:
    13,323
    You can perform a row of raycasts from old to new sword position.
     
    MaximumTre likes this.
  8. MDADigital

    MDADigital

    Joined:
    Apr 18, 2020
    Posts:
    2,198
    We have no problems with this even before Continuous speculative was a thing.



    No raycast or nothing just collision enter check and if force is from right angle and with enough force we return the action

    Edit: btw animation drives the sword not physics? I wonder how well that will work.
     
    Last edited: Oct 19, 2020
    ToadMedicine likes this.
  9. MaximumTre

    MaximumTre

    Joined:
    Nov 28, 2015
    Posts:
    163
    Not sure what you are getting at here. It's a third person game and the attacks are animations, why wouldn't the animations drive the sword? Am I missing something? It works reasonably well now that I'm checking to make sure the enemy is in range. Now all of my hit checks are working as intended, no matter how fast the attacks come.

    Sorry for the late post, I've had health issues to deal with.

    Edit: I just realized after posting this that some people use the actual weapon as the strike point. I don't like doing this, I'd rather just make sure the target is in range when the animation reaches the point when the actual damage should register. Is that what you were getting at?
     
  10. MDADigital

    MDADigital

    Joined:
    Apr 18, 2020
    Posts:
    2,198
    Normally how you do that is that you have a ghost transform that is driven by the animation. Than you move the actual transform with physics.
     
  11. kdgalla

    kdgalla

    Joined:
    Mar 15, 2013
    Posts:
    4,355
    That's how it's done for active ragdolls, for example. This is a good option if you're making a very physics-based game, but I don't think that's how melee attacks are "normally" done. I'm pretty sure a majority of games just use animations.

    Unity's own 3D game kit implements this method well. It's a good example for anyone who needs it.
     
    angrypenguin likes this.
  12. MDADigital

    MDADigital

    Joined:
    Apr 18, 2020
    Posts:
    2,198
    Sure but if your sword hits another rigid body do not expect perfect results with that method