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

How to program throws

Discussion in '2D' started by hasen, Apr 10, 2015.

  1. hasen

    hasen

    Joined:
    Apr 1, 2015
    Posts:
    29
    I'm new to unity and am a beginner in coding. I can see how to make the basics of a 2D platform shooter or fighter and how to program impacts from hiring or kicking/punching etc but I'm a bit puzzled as to how throws and holds are programmed. I would assume that both the attacker and defender will need to initiate some kind of animation as if they were one at the point a throw or hold is successfully initiated?

    Thanks.
     
  2. hasen

    hasen

    Joined:
    Apr 1, 2015
    Posts:
    29
    Hmm....no one knows...
     
  3. GarBenjamin

    GarBenjamin

    Joined:
    Dec 26, 2013
    Posts:
    7,441
    I am sure many people know they either have not read the question yet or are too busy to leave a reply. :)

    I generally see everything as a sequence of actions or states. So off the top of my head I would do something like this:

    Define some states for Throw for both the Thrower and the Target like ThrowerGrabTarget, ThrowerLiftTarget, ThrowerThrowTarget and TargetGrabbedForThrow, TargetLiftedForThrow, TargetThrown.

    When the player has requested to throw a target and the tests for proximity and so forth have been performed to determine the action is valid begin the sequence. The thrower notifies the target it has been grabbed so the target enters the TargetGrabbedForThrowState and the player enters the ThrowerGrabTarget state which each doing the appropriate animation. The thrower will drive the sequence so when it proceeds to ThrowerLiftTarget state it notifies the target to enter TargetLiftedForThrow state and so on. Of course, in the grab state you may want to let the target attempt to escape from the hold.

    Alternately you could simplify it to just the thrower does the grab, lift and throw animation all in one and the target performs the being grabbed, being lifted and being thrown animation and movement all in one. I just prefer to break everything down both for simplicity and to have more control over everything.
     
  4. hasen

    hasen

    Joined:
    Apr 1, 2015
    Posts:
    29
    Ok thanks for your help that gives some ideas. Pity there aren't any tutorials online for versus fighting games in unity? Surely they would cover it more but I couldn't find any at least in my searches.
     
    BrandyStarbrite likes this.