Search Unity

  1. Unity 2018.1 has arrived! Read about it here
    Dismiss Notice
  2. Scriptable Render Pipeline improvements, Texture Mipmap Streaming, and more! Check out what we have in store for you in the 2018.2 Beta.
    Dismiss Notice
  3. If you couldn't join the live stream, take a peek at what you missed.
    Dismiss Notice
  4. Improve your Unity skills with a certified instructor in a private, interactive classroom. Learn more.
    Dismiss Notice
  5. ARCore is out of developer preview! Read about it here.
    Dismiss Notice
  6. Magic Leap’s Lumin SDK Technical Preview for Unity lets you get started creating content for Magic Leap One™. Find more information on our blog!
    Dismiss Notice
  7. Want to see the most recent patch releases? Take a peek at the patch release page.
    Dismiss Notice

Motion Controller

Discussion in 'Assets and Asset Store' started by Tryz, Feb 21, 2014.

  1. Necka_

    Necka_

    Joined:
    Jan 22, 2018
    Posts:
    102
    Coming back with some feedback on my tests

    I tried with the State Machine Behaviour and I didn't like the results I've got.

    I remembered I've worked on the custom event script that intercept Combat Messages and send them as a custom event into Bolt.

    So I did an expose combat message and saw that I have everything I need there. I can use the Attack Index to spawn different slash/hit particles depending on the attack, and even modify it based on impact power. Good, very good (love your message system Tim)

    So as a prototype (the final won't be an Expose and have lots of derivation depending on attack style/impact power - also instead of instantiate I'll probably use pooling) I've set a simple "launch the particle trail from the mount point "right hand" position/orientation and spawn a hit particle on the hit transform of the enemy"

    It works quite good, need to tune some stuff though.
    upload_2018-6-20_0-24-42.png

    My issue here is that I'm using the combat message: "MSG_COMBAT_ATTACKER_ATTACKED = 1101"

    It only spawn the particles when the attack is directed to an other actor combatant. For the Hit particles it's ok, but I'd like to have the slash trails even if hitting nothing

    Before I tried with the pre-attack message and from the video I saw it's clearly not the right one (it spawn particles as soon as I hit the attack button, too soon and even without attack animation going on)

    Then I tried "MSG_COMBAT_COMBATANT_ATTACK = 1002;" but it does nothing at all...

    Is there a way to have what I want in this case? Or would it require for you Tim to create a custom message?

    Thanks for your input

    Ah, also my second question from my first post is still valid (slowing down the end of an animation)

    thanks
     
  2. Tryz

    Tryz

    Joined:
    Apr 22, 2013
    Posts:
    2,762
    Personally, I'd spawn weapon particles and hit particles from the weapon. The SwordCore inherits from WeaponCore and provides the basis for melee weapons. By inheriting from SwordCore, you could override some key functions and spawn your particles:

    OnStartSwing(CombatMessage rCombatMessage);
    OnEndSwing(CombatMessage rCombatMessage);
    OnImpactComplete(CombatMessage rCombatMessage);

    The "CombatMessage" grows over time. So, by the time you get to OnImpactComplete, it includes the actual point that was hit, the defender, etc.

    While I haven't done particles like that yet, inheriting from SwordCore seems like the right place to start.

    You can slow the animations by changing the "Speed" property on Unity's animator component:
    https://docs.unity3d.com/ScriptReference/Animator-speed.html

    In the MC, you can access the animator off of the Motion Controller while in a motion. Like this:
    mMotionController.Animator.Speed = 0.5f;

    Just make sure you reset the speed as the animator will keep the speed for all animations it runs.
     
  3. Tryz

    Tryz

    Joined:
    Apr 22, 2013
    Posts:
    2,762
    I see what you're saying about it auto-starting when at the top. It makes sense because without the Action Alias, you're in a valid place to climb down.

    I think you'll want to customize a motion to not do the climb down automatically. What I'd do inherit from ClimbLadder.cs and then override the TestActivate() function.

    If you look at line 264 and line 271, you'll see two functions TestForClimbDownBack() and TestForClimbDownFoward(). You just want to prevent those from returning 'true' if you've just come from the Climb Ladder motion.


    If you don't want to create your own motion, you could do all this by tapping into the MC's Unity Events. For example, there's an "On Test Activate" event. You can create a small handler for that and change the message's "Continue" property to false if you just came from the Climb Ladder motion.




    I prefer the inherited motion route, but I get that may be scary for some.
     
  4. Tryz

    Tryz

    Joined:
    Apr 22, 2013
    Posts:
    2,762
    Weird this didn't show up until after I just posted. o_O

    That's really cool that you can tap into it from Bolt... nice. :)

    Ah. As you mentioned, the pre and post messages aren't really synced with an animation. They just trigger as the motion is activated or deactivated.

    There is no separate message pair for when the swing starts, but you could tap into the SwordCore as a I mentioned in the post I just sent.

    On thinking about it more...

    The problem with adding messages to the SwordCore.OnSwingStart or to the BasicMeleeAttack is that my animation events are occurring when the attack is valid to contact. That probably isn't the right point for a swoosh-arc particle system to start and stop.

    I think the best things for you to do is to add your own animation events to the animations you have. Then, you can position the start/end pair regardless of my 'hit' pair. You'd then have a component listening for those animation events and turning on/off the swoosh particles as needed.

    I haven't tried this, but I think that's the way I'd go to have full control over the start/stop.
     
    TeagansDad likes this.
  5. Harekelas

    Harekelas

    Joined:
    Feb 3, 2015
    Posts:
    494
    I just recorded the height when the actor's velocity y turn from positive to negative. Then when he's about to land I check the delta height, set up several rules for like: when the delta height is smaller than 2 he uses normal landing; 2 to 10 uses hard landing and consume his stamina or health according to the exceeded distance from 2 meters; bigger than 10 he simply dies.
     
    Tryz likes this.
  6. Harekelas

    Harekelas

    Joined:
    Feb 3, 2015
    Posts:
    494
    Hi Tim,
    I'm wondering how can I serialize a custom struct in one of my motion, I'll need to draw it on the motion controller inspector but found it can not be serialized, all modifications in the inspector will be lost when the memory is dis-allocated.
    Any API from ootii's editor extension that I can use?
     
  7. Necka_

    Necka_

    Joined:
    Jan 22, 2018
    Posts:
    102
    Hi Tim,

    thanks for both your answers and ideas on this topic and on the animation speed, I'll try that at home

    I like the idea of animation events in this case! I can still use anyway the combat message for the Hit particle as it is clearly working great

    The only thing is that I never used animation event. I know how to set them (I have 4 motions that chain together in a combo, so I used those events, but those are set by you already) but I don't know how to listen to them.

    If it's particles with auto destroy or no loop, I believe I just need to set a "StartSwoosh" not an end

    Is there a simple way to listen to this animation event within MC or is it Unity stuff?
    I would just need a simple example so I can try to translate it into Bolt and have unlimited power (or not :D)

    thanks
     
  8. Tryz

    Tryz

    Joined:
    Apr 22, 2013
    Posts:
    2,762
    Necka_ likes this.
  9. Tryz

    Tryz

    Joined:
    Apr 22, 2013
    Posts:
    2,762
    Unfortunately, there's no good way to do this.

    MonoBehaviours don't allow lists of derived types and ScriptableObjects can't be stored as prefabs.So, I had to serialize my motion lists myself and that approach doesn't support new types. Over time, I've evolved how I serialize things but I haven't moved that into the MC because I don't want to break everyone's existing motion list.

    So, the best thing to do is store your information as an external MonoBehaviour on the character and then access that information from the motion using GetComponent<XXX>().

    [EDIT]
    Another trick you can do is serialize your struct into a string property and that will get saved. You would deserialize in the motion's Awake() function and serialize in the OnInspectorGUI().

    I haven't done this in a motion, but I do this in other assets. It should work.
     
  10. Necka_

    Necka_

    Joined:
    Jan 22, 2018
    Posts:
    102
    Hi Tim

    Your last idea was very good, it works super fine and it is very easy to setup

    upload_2018-6-20_22-55-55.png

    I was just wondering (I'm not into code + how much this or that is expensive) if those animation events triggers are expensive and if it will follow up with multiple ennemies and fast paced action
     
  11. Tryz

    Tryz

    Joined:
    Apr 22, 2013
    Posts:
    2,762
    I've never done any performance tests on them directly, but they are a core Unit features. So, I'd assume you'll be fine to use them.
     
  12. recon0303

    recon0303

    Joined:
    Apr 20, 2014
    Posts:
    1,343

    if it was mobile, I would be worried about it, since its PC, I assume your fine. typically. Check the Profiler as well. but typically for PC your fine.
     
    Necka_ likes this.
  13. Necka_

    Necka_

    Joined:
    Jan 22, 2018
    Posts:
    102
    Hello,

    So I managed with no issue to create a whole 1 handed sword flow that just uses a different Form (8000 for the test)

    The only struggle I have is that the Equip Motion doesn't actually equip the Sword I have defined. It works if I set the Form to 100 in the inventory (but that's the wrong animation then), but when I set it to 8000 (and have also my Animator state with this requirement) the animation works, but the sword doesn't come out.

    So I'm missing a point that is probably obvious here. While I found out for IDLE, IDLE Pose and Exit, the new form blended tree, everything worked out, but just this point is a mystery for me now

    Here are my settings:

    upload_2018-6-21_14-47-25.png
    upload_2018-6-21_14-47-35.png

    Edit: also the other mystery for me is the Motion Phases definition. I saw for example 3150 and 3155 for the original sword and shield. I do not realise what those are and where they are defined; maybe it's actually my issue
     
  14. Tryz

    Tryz

    Joined:
    Apr 22, 2013
    Posts:
    2,762
    If I had to guess, your new equip animation doesn't have an animation event at the time you want the sword created. If you look at my "draw sword 1" animation, you'll see this:



    That's the point in the animation where the motion creates the weapon you've defined in the weapon set.

    "Motion Phases" are just integers. I use them to control the flow of the animations/motions. They are the conditions on the transitions in the animator.

    Think of the "Motion Phase" as what we're doing and the "Motion Form" as the form that action will take. For example:

    Motion Phase 3150 says "Equip a sword"
    Motion Form 100 says "Equip a sword with Tim's animation."
    Motion Form 8000 says "Equip a sword with Necka's animation."
     
  15. TeagansDad

    TeagansDad

    Joined:
    Nov 17, 2012
    Posts:
    590
    @Necka_ - Also check your transition time into your Equip animation. It defaults to 0.25s, but if you're still transitioning when the Animation Event occurs, it won't be received.

    You can see in the preview on the transition from Any State if this is happening. If it is, try a transition time of 0.1 to 0.15
     
    Tryz likes this.
  16. Necka_

    Necka_

    Joined:
    Jan 22, 2018
    Posts:
    102
    Oh my god I feel so stupid right now. I did check the animation event because since our talk yesterday, I'm playing a lot with them and love it. But yeah, guess which animation clip I checked for event? mine :D of course there were no events... I'm sorry that was dumb :D

    But at least I won't forget that now, and I understand better the motion phases too

    @TeagansDad: thanks for that too, I need indeed to modify the transition speed
     
  17. Necka_

    Necka_

    Joined:
    Jan 22, 2018
    Posts:
    102
    I'm not sure how to manage this as I found the Animator.Speed function (if it's called a function) but nothing that is related to mMotionController.Animator.Speed (In bolt) maybe I'm not checking in the proper types (just checked in MotionController and also in MotionController.Motion

    My issue is that when I slow down the animation (at the start of the Combo chain) if the player press the attack button in the good timing I wanted that the animation speed reset; I'll probably need to be super creative for this one I guess
     
  18. TonyLi

    TonyLi

    Joined:
    Apr 10, 2012
    Posts:
    7,923
    Dialogue System for Unity 2.0.1 Now Has Motion Controller Integration

    Just posting a quick note that the Dialogue System for Unity now has support for Motion Controller, courtesy of developer Chris Lasting.
     
    Necka_ likes this.
  19. Necka_

    Necka_

    Joined:
    Jan 22, 2018
    Posts:
    102
    That sounded very simple in my head, but I can't find in the documentation or on this forum how to adapt the BasicDamaged motion to play a different animation based on a variable (would be in my case the power of the hit, which I can already grab from a message)

    I have the player (attacker) who hit the defender with Slash1 and that plays on the defender the BasicDamaged motion and its unarmed animation. Ok good, but seeing the other animator states, I don't get how to have my own custom to play

    Like here:

    upload_2018-6-21_23-45-44.png

    So this will happen if the Actor in in motion form 100 (Sword and Shield), fine. But what are those parameters? where do they come from and what influences them?

    To test I just set on my Attacker to have the basic attack to have L0MotionParameter = 40 and I've set on the defender that it plays another animation when the parameter = 40.

    Of course that doesn't work, because the attacker Basic Attack parameter probably doesn't speak to the Defender BasicDamaged parameters

    I tried even to set manually in the BasicDamaged motion the form to something different with no success...

    So I'm a bit lost, I want to do something quite generic where all my actors will react to normal attacks with a normal damaged animation, but could be knocked back on stronger skills or even knocked down on even stronger skills.

    I maybe missed it in the documentation, but really I can't figure out what parameter I should change to influence the damaged motion.

    I don't think it's super complicated to translate the power of my sword attack into different damage animation, or am I doing it with the wrong logic?