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. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice
  4. Dismiss Notice

Swordplay mechanics

Discussion in 'Game Design' started by bobadi, Dec 7, 2020.

  1. BrandyStarbrite

    BrandyStarbrite

    Joined:
    Aug 4, 2013
    Posts:
    2,068
    How many buttons are you using for attacks?
     
  2. bobadi

    bobadi

    Joined:
    Jan 3, 2019
    Posts:
    594
    one for slashF (front right1), one for slash180 (front left1) *

    *since if you do let's say a (right stance) slash towards left, then you can only do slash right (if that's finished)
    so the direction of slashes always depends on the position of the hand (and stance)


    meaning slashF +
    1. right stick [direction] : 3 attack angles for right and left + 2 angles up and down vertical slash
    (updated input for vertical slash)
    2. left stick [movement] : slashF with forward movement

    for other attacks, like kick or special attack like salto jump slash, will need separate button input

    also thinking about randomizing attacks, so attacks don't look the same (variants)
    like, one hand / two hand weapon holding attacks could be randomized or defined by player style

    update again about vertical slash:
    I thought this method (using neutral direction input for it) messes up the slash direction switch on input
    but might be it's just not implemented yet (only stance switch slash is switching)
    will need handP ( / or state tracking. not stance state yet) for this

    slash direction switching
    needed one more thing, slash counting
    slashswitch03.gif slashswitch04.gif
     
    Last edited: Feb 1, 2021
  3. bobadi

    bobadi

    Joined:
    Jan 3, 2019
    Posts:
    594
    bummer. rund into a unity build bug

    • raycasts doesn.t register

    tried 2020.1 build, but same thing

    looked up like 4 threads, but none of them has answer, this thread has problem identification (tag scrapped on build), but not my case, I'm not using tag for detection. and debug.logd on development build, the layer, which is there

    have one more tip, that changing linecast to raycast and check if that work.



    5.6 still has 15% better performance. URP might do better, since the thing looks to come from rendering (drawcalls)
     
  4. Antypodish

    Antypodish

    Joined:
    Apr 29, 2014
    Posts:
    10,582
    What do you mean by that?
     
  5. bobadi

    bobadi

    Joined:
    Jan 3, 2019
    Posts:
    594
    raycasts don't work on (win) build.

    red doesn't turn yellow
    slashswitch05.gif
    slashswitch06.gif
     
    Last edited: Feb 2, 2021
    BrandyStarbrite likes this.
  6. bobadi

    bobadi

    Joined:
    Jan 3, 2019
    Posts:
    594
    anyway. the first prototype demo is here

    NEEDS GAMEPAD
    Renegade 0.99 locomotion system can be tried with keyboard

    link removed
     
    Last edited: Feb 3, 2021
  7. bobadi

    bobadi

    Joined:
    Jan 3, 2019
    Posts:
    594
    found out in development build why the raycast wasn't working

    swordcollider was turned off and had a line in start
    ID = swordColl.GetInstanceID();
    and missing object error messed up the build
    and was fine in editor

    changed code to RayCastAll and some small bits

    updated the demo

    green is kinematic rigidbody + trigger collider
    red is only trigger collider
    white is nonkinematic rigidbody + collider

    rsword.jpg
     
    BrandyStarbrite likes this.
  8. bobadi

    bobadi

    Joined:
    Jan 3, 2019
    Posts:
    594
    added stab and slash 360

    stabN360.gif
     
    BrandyStarbrite likes this.
  9. BrandyStarbrite

    BrandyStarbrite

    Joined:
    Aug 4, 2013
    Posts:
    2,068
    That is nice.
     
  10. BrandyStarbrite

    BrandyStarbrite

    Joined:
    Aug 4, 2013
    Posts:
    2,068
    @bobadi
    Holy cakes, that is cool!:D
     
  11. bobadi

    bobadi

    Joined:
    Jan 3, 2019
    Posts:
    594
    oops. moved post to here

    there is some issues to work out full handling of enemies


    would it make sense if only used vertical slash as a finishing move?

    now first you need to push stick before pressing button for slash
    (to avoid 0 value, which triggers vertical slash)

    added movement rotation and run (doesn't look too good)
    swordmove.gif
    also left and right turn (but feels a bit unresponsive, must release button [frontL2])
    swordturns.gif
     
    Last edited: Feb 3, 2021
    BrandyStarbrite likes this.
  12. bobadi

    bobadi

    Joined:
    Jan 3, 2019
    Posts:
    594
  13. BrandyStarbrite

    BrandyStarbrite

    Joined:
    Aug 4, 2013
    Posts:
    2,068
    I don't mind checking it out, but my PC is down.
    But anyway, how is your sword animations these days?
     
    Antypodish likes this.
  14. bobadi

    bobadi

    Joined:
    Jan 3, 2019
    Posts:
    594
    sorry had no news

    last two days been workin on it
    first took care of the root rotation glitch that is a curse of a system like this
    which allows transitions from almost any state/pose to any other state/pose

    it happens when transitioning between poses like these
    because root rotates between the smaller angle,
    so it spins to the right
    [the root direction indicated by red arrow]
    glitch1.jpg glitch0.jpg

    also happens for example
    if want to go from 180RStance to RStance L>R slash

    what I did:
    made it to transition to stance if input given for this
    (based on root rotation and hand position)

    could also use/remake animations that root doesn't rotate that much
     
    Last edited: Mar 21, 2021
    BrandyStarbrite likes this.
  15. bobadi

    bobadi

    Joined:
    Jan 3, 2019
    Posts:
    594
    and a dozens of small improvements

    slash w stance-switch mixed with 180 slashes
    sword2103a.gif

    regular slash + stance-switch slash
    sword2103b.gif
     
  16. bobadi

    bobadi

    Joined:
    Jan 3, 2019
    Posts:
    594
    integrated limb hacker but there are issues

    - it seems to only work on meshes w one renderer (no multi-obj meshes)
    - a minor one: for decent results the mesh must be watertight
    - not limited by blade penetration (or orientation)

    limbhack1.gif limbhack2.gif
     
    Last edited: Mar 25, 2021
  17. bobadi

    bobadi

    Joined:
    Jan 3, 2019
    Posts:
    594
    have to break away from this, drives mi crazy

    stopping slash with IK, maybe not a good idea*
    kinda works, but not the best
    blockd.gif
    basically this is the code used (for IK target), but it's not precise when bared down

    Code (CSharp):
    1. forward = lookatT.position - swordRoot.position;
    2. swordR = Quaternion.LookRotation (forward, upDir);  //upDir is sword.up
    3. angle = Quaternion.Angle (swordRoot.rotation, swordR);
    4.  
    5. transform.position = rightHand.position;
    6. transform.rotation = swordR;
    7. transform.Rotate (0, -angle, 0);
    8.  
    *could use animation that moves in the opposite direction
    but it's not slash stop
     
    Last edited: Mar 25, 2021
  18. bobadi

    bobadi

    Joined:
    Jan 3, 2019
    Posts:
    594
    okay so I saw this video

    and the right code for this is
    Code (CSharp):
    1. forward = hitPoint - swordRoot.position;
    2. Vector3 RDir = Vector3.RotateTowards (swordRoot.up, forward, 360, 0); //using  .forward or .right doesn't change anything
    3. Quaternion targR = Quaternion.LookRotation (RDir);
    4. ikx.rotation = targR;
    this looked right
    blockdmethod2.jpg
    blockd_meth2.gif

    then adding rotation to it slash direction taken into account
    Code (CSharp):
    1. if(Renegade.comp.swordMX.actNow.sidex == -1)
    2.                                         tracerHits.onSlashBlock.ikx.Rotate (180, tracerHits.onSlashBlock.angCorrR, 0);
    3. if(Renegade.comp.swordMX.actNow.sidex == 1)
    4.                                         tracerHits.onSlashBlock.ikx.Rotate (0, tracerHits.onSlashBlock.angCorrL, 0);
    and adding elbow IK, timers etc
    the final result looks like this
    blockd_final.gif
     
    BrandyStarbrite likes this.
  19. bobadi

    bobadi

    Joined:
    Jan 3, 2019
    Posts:
    594
    finally can edit animations frame-by-frame
    [the yellow line is the edited, white is the original]
    curveeditin02a.gif
    but
    if want shoulder rotation have to use easyIK or fastIK
    but both of those have different rotations than the built-n IK

    can try finalIK or CCDIK if that would work
     
  20. BrandyStarbrite

    BrandyStarbrite

    Joined:
    Aug 4, 2013
    Posts:
    2,068
    Wooah! That whole decapitation animation looked brutal. That looked more brutal and more credible, than the fatalities in Mortal Kombat 11.:eek:

    Great work there bobadi.:D
     
  21. bobadi

    bobadi

    Joined:
    Jan 3, 2019
    Posts:
    594
    BrandyStarbrite likes this.
  22. bobadi

    bobadi

    Joined:
    Jan 3, 2019
    Posts:
    594
    added Renegade to be notified when and on which bone the slicing happens
    (so can play reaction animation, switching off Renegade, sword dropping etc based on this info
    but this is sometimes erratic, seems like not always that bones is passed)


    also added layer check and colliders to be ignored for the slicer
    (+explicitely disable ChildOfHackable.cs on sword, which might be because it is added on all objects
    with collider in the hierarchy, have to check this)


    and another turn style

    one-on-one swordplay [2 gamepads]
    https://www.mediafire.com/file/v5vvqzoilq0acm9/R99SWORDB.ZIP/file
    sword2GP.jpg

    and another limitation of limbhacker:
    cannot have other objects under root, because then it doesn't find the skeleton bones
     
    BrandyStarbrite likes this.
  23. BrandyStarbrite

    BrandyStarbrite

    Joined:
    Aug 4, 2013
    Posts:
    2,068
    @bobadi
    So how is this project going? Did you make anymore good progress?
     
  24. bobadi

    bobadi

    Joined:
    Jan 3, 2019
    Posts:
    594
    hi!
    no. if I look at the modified date of swordMX, it's 4.21, so no. it's part of the Renegade system.

    will have to take a look at it sometime how to progress further, if you have some idea, shoot
     
    BrandyStarbrite likes this.