Search Unity

  1. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice

Motion Controller

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

  1. dswigger

    dswigger

    Joined:
    Aug 9, 2019
    Posts:
    12
    @TeagansDad I have about 4 different walking loops I want to use on different characters. I started down the path of basically copying the runwalkrotate_v2 script and then realized it uses blend tree's instead of the previous SM which used phaseIds. So I am thinking I can either try and get the blend-tree instance and set my new animation or copy the SM for walking and replace the one animation(which seems like a bad idea but who knows). Appreciate your thoughts.

    -David
     
  2. MilesSmiles

    MilesSmiles

    Joined:
    Nov 27, 2012
    Posts:
    115
    Wondering if someone can help with this? Does anyone have settings they can share for 2.5D sidescroller? I'm trying to prevent the character from being able to turn up or down if you press W or S. I wish there was a 2.5D sidescroller demo in the pacakge.
     
  3. MilesSmiles

    MilesSmiles

    Joined:
    Nov 27, 2012
    Posts:
    115
    How would I setup a death if the player falls? I have the Health attribute. Not sure how to setup the Events.

    Thank you!
     
  4. pedropla

    pedropla

    Joined:
    Apr 9, 2018
    Posts:
    13
    If you are using one of the packages that has ActorCore you can use the ActorCore and reactors as an easy way to invoke the death sequence.
     
    Tryz likes this.
  5. MilesSmiles

    MilesSmiles

    Joined:
    Nov 27, 2012
    Posts:
    115
    Thanks. So I need to buy a package like the weapon one?
     
  6. Tzirrit

    Tzirrit

    Joined:
    Sep 9, 2014
    Posts:
    9
    I was wondering if the Character Controller in general - or the Sword & Shield Motion Pack in particular - support left hand IK for two handed weapons.

    Did some digging in the documentation and on the website, but all I could find was information regarding the shooter motion pack and rifles. Is it possible to easily set up IK for two handed melee weapons?

    Thanks ;)
     
  7. TeagansDad

    TeagansDad

    Joined:
    Nov 17, 2012
    Posts:
    913
    The more "modern" approach to this is the use of the Motion Form parameter. It's generally used to select which particular animation clip to play while still using the same motion logic for all of them. Basic WalkRunPivot and Basic WalkRunStrafe provide examples of this (in conjunction with one or more of the Motion Packs).

    So you would use the same Phase ID for all four of you walking states but use a different Motion Form for each. You can pass the Form into the ActivateMotion call, or you can set the CurrentForm state on the Actor Core component.

    (The motion packs set the Form value on the Actor Core when a weapon is equipped or unequipped).
     
  8. bavollee

    bavollee

    Joined:
    Jan 26, 2016
    Posts:
    17
    Hi, just know this awesome plugin from CameraController. So I bought it and hope it can speed up my games.
    After reading the guide (http://www.ootii.com/Unity/MotionController/MC2Guide.pdf), I don't know what's the generate of motion script and definition script.
    If I add my custom motion, should I generate those two parts? And after generate, how I use the clipboard, it cames hundreds of lines code.
    And also, what's the 'create animator state machine' and 'create input manager settings'.
    MC_question.jpg
     
  9. TeagansDad

    TeagansDad

    Joined:
    Nov 17, 2012
    Posts:
    913
    I've never set it up as a 2.5D controller, so I'll have to give it some thought (also I'm answering on my phone so I don't have the code handy). You don't want to freeze the character's Y rotation though (as you've already seen). Might be as simple as restricting or ignoring the "vertical" axis that is fed to the walk/run motion

    Try using Basic WalkRunPivot (as opposed to the WalkRunPivot that has all the start/stop and turning animations).

    You can try increasing the speed of the walk animation in the blend tree. Set the walk speed if the motion back to 0 and just adjust it in the animator.

    You can also try using a different set of walking animations. Some of them do move faster than the included animations.
     
  10. TeagansDad

    TeagansDad

    Joined:
    Nov 17, 2012
    Posts:
    913
    The Motion Controller exposes a few of the standard Unity Events which you can hook up in the inspector -- MotionActivated and MotionDeactivated will generally be the relevant ones.

    For death/damage due to falling, you'll probably need to track the total distance fallen for that particular activation of the motion. It's a feature that really should be added the the Fall motion. I've got it on my to-do list, but I'm still struggling to finish the set of updates I've already been working on the past few months. :)

    No... The ActorCore is part of the base MotionController package, as are the BasicDamaged and BasicDeath motions (as well as the Reactors which activate them).
     
    Tryz likes this.
  11. TeagansDad

    TeagansDad

    Joined:
    Nov 17, 2012
    Posts:
    913
    The Sword & Shield pack does not support left hand IK for two-handed weapons (out of the box). Both the Archery and Shooter packs do use IK to adjust and position. You may be able to adapt some of that code. Alternatively, you could use Bone Controller, FinalIK, or another IK asset for this.

    Yet another item on my very long to-do list. ;)
     
    Tryz and Tzirrit like this.
  12. TeagansDad

    TeagansDad

    Joined:
    Nov 17, 2012
    Posts:
    913
    Generate Motion Script will generate all of the code to recreate the state machine for theathe motionomotion, including all of its animator states and transitions. It also generates code used by the motion to monitor what state or transition is current while the motion is running.

    Generate Definition Script will generate the code used to recreate the motion's animator state machine in a (mostly) nondestructive way -- it's primarily used for extending the "Basic" set of motions by adding new states to an existing state machine that use the same script logic but use the MotionForm parameter to select a different clip.

    These "Basic" motions are designed to be extensible via the animator controller, and thus there's no real value in generating the code to store hash IDs for runtime querying of the current animator state or transition (as the above script does).

    Create Input Manager Settings will add the motion's default input aliases to the Unity project's input manager. I think this gets called automatically somewhere anyway.

    Create Animator State Machine will ... Well exactly what it says. :cool: It will create the state machine for the motion, set up transitions, and assign the animation clips. You can start with an empty Animator Controller and add each motion's statemachine this way.

    If your custom motion doesn't need to support multiple animation sets that use the same underlying logic, then use Generate Motion Script and paste the code into you motion file. If your script logic is dependent on knowing the current animator state, then you'll want to use this.

    Don't use both code generation options for the same motion though.
     
    Tryz and bavollee like this.
  13. bavollee

    bavollee

    Joined:
    Jan 26, 2016
    Posts:
    17
    Thankyou, TeagansDad. So nice and sweet. I get a lot from your answers.
    I'll keep trying and enjoy it!
     
    Tryz and TeagansDad like this.
  14. bavollee

    bavollee

    Joined:
    Jan 26, 2016
    Posts:
    17
    Hi, one more question, I had enterd the error with Unity 2019.4.1, almost every button I try to test, it comes the error:
    EndLayoutGroup: BeginLayoutGroup must be called first.
    UnityEditor.EditorGUILayout:EndVertical()
    MotionControllerEditor:OnBasicInspector() (at Assets/Plugins/ootii/Editor/MotionController/Actors/AnimationControllers/MotionController/MotionControllerEditor.cs:448)
    MotionControllerEditor:OnInspectorGUI() (at Assets/Plugins/ootii/Editor/MotionController/Actors/AnimationControllers/MotionController/MotionControllerEditor.cs:353)
    UnityEngine.GUIUtility:processEvent(Int32, IntPtr)
    MC_error.jpg
    After searching the solution, https://forum.unity.com/threads/endlayoutgroup-beginlayoutgroup-must-be-called-first.523209/, but it couldn't be work.
     
  15. TeagansDad

    TeagansDad

    Joined:
    Nov 17, 2012
    Posts:
    913
    @bavollee - I have seen this error from time to time in Unity 2019.4 as well. I have now been able to trace it to calling EditorUtility.DisplayDialog() inside of a GUI layout group. It happens both when called between Begin/End methods such as EditorGUILayout.BeginVertical and EditorGUILayout.EndVertical as well as inside of a disposable GUI Scope such as using (new EditorGUILayout.VerticalScope) { ... }

    Calling GUIUtility.ExitGUI() directly after the call to EditorUtility.DisplayDialog() fixes the error.

    However, this error is benign and doesn't actually affect anything that you're doing, so I wouldn't worry about trying to fix it. I'll refactor all of the EditorUtility.DisplayDialog() calls in the custom inspector code into a new method in EditorHelper.cs that takes care of calling GUIUtility.ExitGUI() after showing the dialog box.

    Thank you for bringing this to my attention. I had seen it show up a few times after updating to Unity 2019.4 when setting up Motion Packs but I virtually never use the Basic inspector so I wasn't even thinking looking at the DisplayDialog() as a problem.
     
    Tryz and bavollee like this.
  16. TeagansDad

    TeagansDad

    Joined:
    Nov 17, 2012
    Posts:
    913
    Sorry, I had forgotten about this.

    Code (CSharp):
    1. using com.ootii.Actors.Magic;
    2. using UnityEngine;
    3.  
    4. namespace SpellTests
    5. {
    6.     public class TestSpellAction : SpellAction
    7.     {
    8.         public TestSpellData TestData;
    9.  
    10.         public override bool OnInspectorGUI(Object rTarget)
    11.         {
    12.             bool lIsDirty = base.OnInspectorGUI(rTarget);
    13.  
    14.             if (TestData == null)
    15.             {
    16.                 TestData = new TestSpellData();
    17.                 lIsDirty = true;
    18.             }
    19.  
    20.             if (TestData.OnInspectorGUI()) { lIsDirty = true; }
    21.  
    22.             return lIsDirty;
    23.  
    24.         }
    25.     }
    26. }
    Code (CSharp):
    1. using System;
    2. using System.Collections.Generic;
    3. using com.ootii.Helpers;
    4.  
    5. namespace SpellTests
    6. {
    7.     [Serializable]
    8.     public class TestSpellData
    9.     {
    10.         public string MagicName;
    11.  
    12.         public List<int> MagicPower;
    13.  
    14.         int ListCount = 0;
    15.  
    16.         public bool OnInspectorGUI()
    17.         {
    18.             bool lIsDirty = false;
    19.  
    20.             if (EditorHelper.TextField("MagicName", "", MagicName))
    21.             {
    22.                 lIsDirty = true;
    23.                 MagicName = EditorHelper.FieldStringValue;
    24.             }
    25.             if (MagicPower == null)
    26.             {
    27.                 lIsDirty = true;
    28.                 MagicPower = new List<int>();
    29.             }
    30.             ListCount = MagicPower.Count;
    31.             if (EditorHelper.IntField("Count", "Count of List", ListCount))
    32.             {
    33.                 ListCount = EditorHelper.FieldIntValue;
    34.             }
    35.             if (ListCount != MagicPower.Count)
    36.             {
    37.                 lIsDirty = true;
    38.                 MagicPower.Clear();
    39.                 for (int i = 0; i < ListCount; i++)
    40.                 {
    41.                     MagicPower.Add(0);
    42.                 }
    43.             }
    44.             for (int i = 0; i < MagicPower.Count; i++)
    45.             {
    46.                 if (EditorHelper.IntField("MagicPower" + i, "", MagicPower[i]))
    47.                 {
    48.                     lIsDirty = true;
    49.                     MagicPower[i] = EditorHelper.FieldIntValue;
    50.                 }
    51.             }
    52.  
    53.             return lIsDirty;
    54.         }
    55.     }
    56. }
    I just did a quick and dirty method of adding to the int list, as you were calling an external method in your code.

    I don't see the "No Content" show up.
     
    Tryz likes this.
  17. bavollee

    bavollee

    Joined:
    Jan 26, 2016
    Posts:
    17
    @TeagansDad , Thank you so much. I got your points. And I had add custom motion like the demos do.
    Your solution and scenario analysis mean a lot to me. I'll learn the way you said.
     
    Tryz likes this.
  18. MilesSmiles

    MilesSmiles

    Joined:
    Nov 27, 2012
    Posts:
    115

    Thanks. I notice you have a 2.5D camera rig but yeah it would be awesome if there was a motion for it. Basic Walk Run Focus almost works but he'll still turn up or down if I press up or down and then the input is backwards on things like the Balance motion.

    I'm trying to custom this in Playmaker but there's so many properties.

    I have Opsive's Third person controller too and it works so im wondering if I can just use his controller but your motions.
     
  19. Gorkadread

    Gorkadread

    Joined:
    Mar 27, 2013
    Posts:
    7
    Hello everyone.

    Been going through the thread for scraps and pieces of information regarding networking with an authorative server and having MC send inputs to the server. It seems others have trod down this path before me and I'm wondering if you'd care to share where you decided to get the inputs and pass it to the server?

    I thought UnityInputSource.cs and the function IsJustPressed(string rAction) was a good place to catch the input and pass it to the server, would you agree? It runs every frame so I guess an event-triggered function would be more appropriate, but not sure there is one.

    Would be most grateful for other ideas concerning where it would be a good idea to catch player inputs for the server.
     
    Last edited: Jul 19, 2020
  20. pedropla

    pedropla

    Joined:
    Apr 9, 2018
    Posts:
    13
    Are you looking for just Server Authority or Server Authority with Client Prediction?

    I'm currently working on adapting MC for Server Authority with Client Prediction using Photon Bolt.

    Here are some of the steps you'll need to do (assuming you are using Photon Bolt and familiar with it):

    Disable all root motion. You technically can use it but it is orders of magnitude more complex to implement than without root motion.

    Inherit from MotionController, ActorController, InputController and CameraController, ActorState.

    Make all inherited classes NOT use Update/FixedUpdate and reimplement them using an update method which doesn't use Unity TimeDelta's and instead uses the TimeDelta of the network frame's you are using. You'll need to do a deep dive into those classes and see what else needs extending.

    Setup all the replication correctly to replicate to all except server and controller. Make sure to replicate camera position/rotation as well since it is used for movement and aiming.

    Implement all of the Reset/Replay of SimulateController to give the logic you want. Ensure it disables animation for any replays.

    Implement the rewind portion to also reset ActorState to the frame being reset to and reset necessary variables to that point in time.

    There are quite a few more details but it would be too much for just a post on the forum.

    Basically, server auth with client prediction is not trivial to implement but I think the MotionController is one of the easiest unity character controllers to implement it in due to its modularity.

    If you just want server auth it might feel more sluggish over a network, especially with any type of lag, but it is a lot easier to implement and wouldn't require disabling root motion. You'd just need to override the input controllers (inherit from the base class and make it get input from wherever you want) and use Bolt commands to send the relevant input to the server and then use SimulateOwner to run it on the server and replicate everything across all.

    Hope this helps. If you are using photon Bolt there's a great discord group where people are generally helpful.
     
    Last edited: Jul 21, 2020
    Tryz and Gorkadread like this.
  21. Zante

    Zante

    Joined:
    Mar 29, 2008
    Posts:
    405
    Fantastic tool but I need some feedback and instruction regarding some unwanted behaviours : ]

    In the video below, you can see my character going up and down stairs. I'm looking for some tips on how to make this more natural. I'm using Final IK and the grounding script to handle the placement of feet.

    1. W̶h̶e̶n̶ ̶g̶o̶i̶n̶g̶ ̶d̶o̶w̶n̶s̶t̶a̶i̶r̶s̶,̶ ̶t̶h̶e̶ ̶m̶o̶v̶e̶m̶e̶n̶t̶ ̶i̶s̶ ̶v̶e̶r̶y̶ ̶j̶e̶r̶k̶y̶.̶ ̶T̶h̶e̶ ̶c̶a̶m̶e̶r̶a̶ ̶s̶h̶a̶k̶e̶s̶ ̶a̶n̶d̶ ̶t̶h̶e̶ ̶h̶a̶i̶r̶ ̶m̶o̶v̶e̶s̶ ̶c̶h̶a̶o̶t̶i̶c̶a̶l̶l̶y̶.̶ ̶W̶h̶a̶t̶'̶s̶ ̶a̶ ̶b̶e̶t̶t̶e̶r̶ ̶a̶p̶p̶r̶o̶a̶c̶h̶ ̶t̶o̶ ̶f̶i̶x̶i̶n̶g̶ ̶t̶h̶i̶s̶ ̶(̶i̶s̶ ̶t̶h̶e̶r̶e̶ ̶a̶ ̶w̶a̶y̶ ̶t̶o̶ ̶d̶a̶m̶p̶e̶n̶ ̶f̶a̶l̶l̶i̶n̶g̶ ̶o̶r̶ ̶s̶h̶o̶u̶l̶d̶ ̶I̶ ̶a̶d̶d̶ ̶a̶ ̶r̶a̶m̶p̶)̶?̶ Edit: Fixed, see bottom of post for solution
    2. Is there an easy way to limit movement speed when going up and down steps?
    3. What is the best approach to changing the animation when walking up/down stairs?
      • I can use IK for head direction, maybe I can do the same to keep elbows back etc? Edit: I'm now using IK see bottom of post for solution
    4. Lastly, is it possible to stop the continuous running into a wall we see in the last part of the video?


    Step jerk solution:
    I changed the mesh collider to 'convex'. This effectively turns the stairs into a ramp but the end result is very much acceptable and still allows for IK that looks in place for the surroundings. This is a 'much' simpler approach than other solutions. See image below for instructions for those having similar issues.



    Going down stairs animation:
    I settled on using Ik for this rather than creating an entirely new animation. I added targets for the hands and elbows and lowered the centre of balance all using Final IK and it seems to be working well enough. I just need to add some conditions under which this gets applied (i.e: going downstairs/down a ramp). See the gif below for the animation (ignoring the pose prior to descent).



     
    Last edited: Jul 22, 2020
    Tryz likes this.
  22. Gorkadread

    Gorkadread

    Joined:
    Mar 27, 2013
    Posts:
    7
    Hey Pedropla and wow, thanks a bunch! These are some really great pointers for me to dissect once I get the basics with input done. I'm not using Photon-Bolt but I guess that you inherit from InputController means you use it? How do you catch the users inputs from keyboard, mouse movement or xbox-controllers? Are you filtering them out from the inputController somewhere?

    Again, thank you so much for this and your time!
     
    Last edited: Jul 21, 2020
    Tryz likes this.
  23. Tryz

    Tryz

    Joined:
    Apr 22, 2013
    Posts:
    3,316
    Hey @MilesSmiles ,

    As @TeagansDad wrote, you don't want to limit the rotation because that will prevent a character from pointing in the right direction (as you're seeing).

    With my existing motions, there's no out-of-the-box way to prevent a character from facing into our out of the screen. I think the simplest approach is to create a custom Input Source that doesn't allow the input (like 'W') to provide a value that keeps the character facing into the screen. I don't think it would be too hard... override the UnityInputSource.cs and in the MovementY, when a value is set to 1 or -1, change it to 0.

    For this, I'd modify the speed of the Mecanim Animator Node. This will keep the character's feet moving at the same speed as his root motion. Just make sure you back up your animator. This way I don't overwrite it when you updated.

     
  24. Tryz

    Tryz

    Joined:
    Apr 22, 2013
    Posts:
    3,316
    I haven't used Playmaker in years, but the same idea as above would work. However Playmaker grabs the input, change the "W" and "S" key (for forward and backwards) to return a nothing or "0". This basically stops you from trying to have your character point into the screen.

    Other than that, you'd need a custom motion that knows you don't want the character pointing up or down the z-axis.

    Unfortunately, no. The motions are built specifically for the Motion Controller and having two character controllers is like having two steering wheels in your car. It wouldn't work well. :)
     
  25. Tryz

    Tryz

    Joined:
    Apr 22, 2013
    Posts:
    3,316
    I just realized @TeagansDad said all this... haha


    @pedropla is right. The ActorCore and Reactors are a good way to trigger this.

    You'll just have to track the falling time yourself to determine if you want to force death or allow a jumping-land. In my Fall motion, you can access the "Age" property. This way if you're falling for more than 2 seconds, you could then force the death when the character's "IsGrounded" property is true.

    So, there's some gameplay logic you have to add, but the big chunks of it should work.

    No, you don't have to. The ActorCore and Reactors exist in the Motion Controller itself.
     
  26. Tryz

    Tryz

    Joined:
    Apr 22, 2013
    Posts:
    3,316
    That's the right thing to do. In AAA games, they typically use a ramp collider for smooth character movement. Then, there's another layer of colliders used for the foot IK. You can see this in modern games like AC Odyssey where the character's feet dangle off steps or intrude if he's not on the right spot. It doesn't affect the main body, just the feet experience. An interesting thing I noticed is that the IK seems to settle once the character stops. It's like they don't even turn it on unless the character stops moving. I'm assuming for performance.

    Not really. It's all based on the root-motion of the animation. I don't do any modification while going up slopes because then the feel look like they slide. You could blend into some advanced movement animations based on the slope you're moving on, but that would require "hiking" animations and customizations.

    I didn't do this because it can get a bit tricky... For example, at what angle do you allow the character to slide against the wall vs. for a stop? If the character is running against a wall, do you want to force a stop if they happen to rotate into that angle for a second?

    It's possible through some customization; by doing a raycast and forcing the input to 0 or the motion to exit. I just felt like I didn't want to make that decision for every game.

    If you want to try, feel free to email tim@ootii.com and I'll try to help.
     
    Zante likes this.
  27. pedropla

    pedropla

    Joined:
    Apr 9, 2018
    Posts:
    13
    Yes, I'm capturing them using the Unity Input system that the InputController uses when I'm on the player and then there's a setting in my InputController for when it's running on the server. When on the server I set the inputs using the Photon Bolt commands that are sent through the network. Hope this helps.

    Out of curiosity, which networking system are you using?
     
  28. pedropla

    pedropla

    Joined:
    Apr 9, 2018
    Posts:
    13
    A more standard fall damage system would be something great to have as a Reactor. *hint hint*. It seems to me something easy to implement and something that would be pretty useful to almost anyone with the MotionController. Can then just give it some setting variables like MinFallDamageHeight, DamagePerFallUnit, and DeathFallUnits, or something like that.

    WDYT Tim?
     
  29. Gorkadread

    Gorkadread

    Joined:
    Mar 27, 2013
    Posts:
    7
    Every little bit helps :) I'm using a custom one built with Lidgren which I started using a couple of years back to learn about networking and it just stuck on me :)
     
  30. Zante

    Zante

    Joined:
    Mar 29, 2008
    Posts:
    405
    Thanks, one more question!

    On the subject of forcing input to 0, this might also answer my question about a way by which I could limit movement speed when using root motions. As my animations have variable speeds depending on the extent to which the analogue stick is being pushed, would limiting the input to a value less than its full extent have the same effect?

    Is this something best done via Ootii or Rewired (my existing input solution)?

    Keeping in mind I have both joypad and keyboard configurations.
     
  31. greatowq01

    greatowq01

    Joined:
    Dec 16, 2018
    Posts:
    21
    Thanks, the issue has been worked out.
     
  32. pedropla

    pedropla

    Joined:
    Apr 9, 2018
    Posts:
    13
    You can adjust animation speed which should affect root motion.

    animator.speed = 0; // animator doesn't run
    animator.speed = 1; // normal speed
    animator.speed = 0.5f; // half speed
     
  33. Artini

    Artini

    Joined:
    Jan 29, 2016
    Posts:
    24
    How long the phase Configuring Scene Objects (Step 2 of 6) during the character setup would take?
    I am using Unity 2019.4.5 and HDRP scene, and the progress bar is at about 30% and do not advance.
    The description says, that it could take 30 seconds or more.
    The character is Genesis 8 Male with simple cloth exported from Daz Studio.
    I have not imported any Motion Packs to the project.
    -----------------------------------
    Never mind.
    I have added motion controller manually and it works.
    Great
     
    Last edited: Jul 30, 2020
  34. Censureret

    Censureret

    Joined:
    Jan 3, 2017
    Posts:
    282
    Okay I feel like I've tried everything i can't seem to get root motion to work when using a character with the ootii components on

    Here is what I've tried:

    Checked the "Use Transform" (the character still has no root motion)
    Disabled the motioncontroller all together (Character still has no root motion)

    outside of this, I have thought of more hacks than I can describe here but nothing has seemed to work.

    Can anyone please help me? :)
     
  35. pedropla

    pedropla

    Joined:
    Apr 9, 2018
    Posts:
    13
    Use Transform should be disabled. Root motion works for the typical setup, but which motions are you using? Your own or the default ones that come with Ootii?

    I know root motion can also be disabled in ootii but I believe it is enabled by default.
     
  36. dswigger

    dswigger

    Joined:
    Aug 9, 2019
    Posts:
    12
    @TeagansDad Hey there. Have you ever made one of your npc's navigate and then sit in a chair? Or other precise navigation type situations. I am struggling with getting him in position to turn around and sit or back up and sit. Either way it seems like I can't get him close enough to the chair. I am using Behavior Designer with your navigation integration. I am using MC and not mesh agent in the action. If I make the stopping distance too small he will never reach the destination, but in situations like this - the destination point is pretty precise. Looking for advice here or even the direction I should take. I am considering when npc gets on side of chair I trigger an animation that actually walks the player around to the position and skip using nav mesh for that part.
     
  37. Censureret

    Censureret

    Joined:
    Jan 3, 2017
    Posts:
    282
    Well this animation is executed by the timeline not the motion controller
     
  38. Censureret

    Censureret

    Joined:
    Jan 3, 2017
    Posts:
    282
    Okay so i wanted to let everyone know how I fixed the (Using timeline with ootii components issue)

    So first of all there is this Magical function called OnAnimatorMove. The motion controller actually uses this to apply root motion. Now when you override this function the root motion is soly determined on the motion controller. And even disabling the motion controller wont help. So I came up with this fun little script:

    Code (CSharp):
    1.     public class TimelineAnimatorRootMotionOverrider : MonoBehaviour
    2.     {
    3.         public bool ShouldOverride { get; set; }
    4.  
    5.         private Animator _animator;
    6.  
    7.         private void Awake()
    8.         {
    9.             _animator = GetComponent<Animator>();
    10.         }
    11.  
    12.         private void OnAnimatorMove()
    13.         {
    14.             if (ShouldOverride)
    15.             {
    16.                 _animator.ApplyBuiltinRootMotion();
    17.             }
    18.         }
    19.     }

    Basically what this does is that once you set "ShouldOverride" to true it will apply the built in root motion of the Animation.

    However since the motion controller is still updating this function you need to disable the motion controller and set the actor controller to "Use Transform"

    To achieve this I used the new unity timeline signal and created the following signal:

    upload_2020-8-4_1-20-35.png

    Here I do 3 things:

    1. Disable the motion controller component
    2. set the ShouldOverride to true (look at the function above)
    3 Set the ActorController "Use Transform" to true

    This works and now to set everything back to normal after the timeline has finished I do the exact opposite :

    upload_2020-8-4_1-21-48.png

    With these two you can apply that before the animation plays and after the animation has stopped playing

    And the timeline looks a little like this:

    upload_2020-8-4_1-22-38.png

    I hope it helps
     
    Tryz likes this.
  39. EnigmaFactory

    EnigmaFactory

    Joined:
    Dec 10, 2011
    Posts:
    92
    Hey all,

    Anyone know when using Camera Controller and Sword and Shield, when NPC strikes me, the Anchor of the camera is dropping to the spine then scrolling up?

    I believe it's due to my Combatant component using Spine, but I'm not sure why Camera would anchor to that after a hit.



    Twitch Video of Behaviour: https://www.twitch.tv/videos/700166244

    Thanks!
     
  40. Smellydave

    Smellydave

    Joined:
    Sep 20, 2013
    Posts:
    4
    Hi,

    Please could someone help me with a problem with Motion Controller,Shooter and Behaviour Designer.

    Most of my enemies are on a plane and work fine using rotate towards nodes but I have put a sniper in a tower and am trying to work out how to make him look and aim down to the floor where the player will be running.
    I am not sure if I need to change something in BD or MC?

    many thanks

    Dave
     
  41. pedropla

    pedropla

    Joined:
    Apr 9, 2018
    Posts:
    13
    You probably need to make your own aim task in BD to aim at an object or a vector3 position. That’s how I’ve done it..
     
    Tryz likes this.
  42. craigjwhitmore

    craigjwhitmore

    Joined:
    Apr 15, 2018
    Posts:
    113
    For the Sword & Shield pack, in the BasicMeleeAttack.Activate(MotinControllerMotion) is there a reason why we aren't caching a copy of ActorCore as a class property and instead making a more expensive call to GetComponent<ActorCore>() on line 380.

    It looks to me like it would be better suited to be a cached property of MotionController.

    Perhaps this is a sledge hammer/nut situation.
     
    Last edited: Aug 10, 2020
  43. Tryz

    Tryz

    Joined:
    Apr 22, 2013
    Posts:
    3,316
    Hey @EnigmaFactory ,

    I see what's going on. The NPC is intruding on the camera's collision area and the camera is trying to compensate for the intrusion... poorly.

    The black arrow represents the direction of the camera. Around our player (orange guy) is a capsule for collision. In the first image below, the NPC hasn't intruded yet.



    This next picture shows the NPC swinging and his collider gets close, but he hasn't intruded yet.



    In this third picture, the NPC's collider goes inside ours. So, the camera thinks there's a collision with something and it's dropping down to calculate it's new position.



    A quick work-around is to change the CC's Collision Layers property to not collide with the layer that your NPC is on.



    For example, move the NPC to a "Characters" layer or something. I typically do this.

    I will look to improve the CC's handling of the intrusion to have it respond better.
     
  44. Tryz

    Tryz

    Joined:
    Apr 22, 2013
    Posts:
    3,316
    That's a good catch.

    I actually do have an ActorCore property on the MC. I'm not sure why I didn't use it.

    I've updated BasicMeleeAttack and a couple of other spots.
     
    craigjwhitmore likes this.
  45. Wolfmoss

    Wolfmoss

    Joined:
    Apr 10, 2015
    Posts:
    2
    Hello Tim and ootii users, I picked up the MC a year or so ago, but am just starting to play around with it now but am having trouble setting it up at runtime via code.

    I'm using an UMA avatar that I'm instantiating in the scene from a prefab at runtime, and whilst everything works as expected if I manually add the MC from the editor menu at runtime and then click the desired movement style button to set up the inputs and character rig, I'm running into the limits of my programming knowledge when trying to replicate the same thing at runtime.

    I've tried adding the MC to the UMA prefab beforehand, and clicking a movement style button to set up the input and camera rig, and then once I've instantiated the prefab at runtime, programmatically hooking up the required connections (eg setting the Anchor property on the camera rig, and the Input Source and Camera Rig properties on the avatar's MC) but after doing this the character isn't responding to any keyboard input (the orbit camera does seem to be attached to the avatar and rotates around the avatar with the mouse as expected).

    After referring to page 31 of the user manual under "Setting Movement Styles at Runtime", I've also tried copying the EnableAdventureStyle() and related methods from the MotionControllerEditor class and putting it into one of my own scripts, so I can effectively simulate the result clicking of a movement style button at runtime, but this is where I run into my aforementioned programming knowledge limits, and am unable to get this transplanted code running.

    The manual refers to 6 steps that the EnableXXXXStyle() methods perform, with "#5 & #6 being what we'll deal with", but I'm wanting to basically achieve steps #1 through to #6 at runtime. If you or someone could point me in the right direction here I would be most thankful.

    (Thanks btw for this great asset! - like many people here, after researching the available MC solutions on the asset store, I went with ootii due to it's extensibility, robust codebase and active support)
     
    Last edited: Aug 18, 2020
  46. Tryz

    Tryz

    Joined:
    Apr 22, 2013
    Posts:
    3,316
    Hey @Wolfmoss ,

    As you're finding, UMA does a lot of run-time generation. With your questions, it sounds like you're trying the "edit-time template/prefab" and I believe that should work.

    If the input isn't working, you probably need to ensure an Input Source (probably UnityInputSource) exists in the scene and your character references that. I use the Input Source so that you can use any input solution that you want.
    Your code would look like this:

    Code (CSharp):
    1. UnityInputSource lInputSource = (UnityInputSource )FindObjectOfType(typeof(UnityInputSource ));
    2. MotionController lController = gameObject.GetComponent<MotionController>();
    3.  
    4. GameObject lInputSourceGO = ((MonoBehaviour)lInputSource).gameObject;
    5. mTarget.InputSourceOwner = lInputSourceGO;
    If you look in MotionControllerEitor.EnableMMOStyle() (line 1892), you'll see the code. However, you will have to poke through it. I have some helper functions like "CreateMotion(...)" and "CreateCameraRig(...)". If you look through those, they will help.

    Honestly, setting up the template/prefab is probably the best way to avoid most of this code. You'll just have to setup things like the input source and camera as you mention. See if the code above helps.

    Here are some earlier posts that may help as well:
    https://forum.unity.com/threads/motion-controller.229900/page-38#post-2836760
    https://forum.unity.com/threads/motion-controller.229900/page-38#post-2837868
    https://forum.unity.com/threads/motion-controller.229900/page-38#post-2838251
     
  47. Wolfmoss

    Wolfmoss

    Joined:
    Apr 10, 2015
    Posts:
    2
    Thanks for your response, @Tryz. The problem with the input not working was actually what I was running into when trying to implement the prefab approach (in reality I think I'm attempting sort of a hybrid code/prefab approach), so if this code snippet is all that I'm missing then it's a much quicker fix than I was expecting! I'll have a crack and see how I go. :)

    Cheers
     
    Tryz likes this.
  48. Censureret

    Censureret

    Joined:
    Jan 3, 2017
    Posts:
    282
    Hello everyone.

    I have a motion where i want to lift the NPC character off the ground (around 3 meters) and then afterwards put him back down.

    But I am having some trouble moving the character

    Here is what I have:

    Code (CSharp):
    1.  
    2.         mActorController.IsGravityEnabled = false;
    3.         mActorController.OrientToGround = false;
    4.         mActorController.FixGroundPenetration = false;
    5.        
    6.         _navMeshAgent.enabled = false;
    7.         _desiredPosition = mMotionController.transform.position;
    8.         _desiredPosition.y = _desiredPosition.y + 3f;
    9.         mMotionController.SetTargetPosition(_desiredPosition, 3)
    10. ;
    I have also tried to set the
    mMovement variable but it doesn't seem to do anything.

    Can you guys help?
     
  49. Tryz

    Tryz

    Joined:
    Apr 22, 2013
    Posts:
    3,316
    Hey @Censureret ,

    The MC.SetTargetPostion(...) function simulates input to move the character using it's motions and animations. It does this using the X & Z axis and ignores the Y axis. So, you can't tell the character to "walk" 3 meters up. If you change setting the ".y" to ".z", you'll see it works.

    To teleport the character, you can use the AC.SetPosition(...) function and the character will pop 3 meters up.
    Code (CSharp):
    1. mActorController.SetPosition(_desiredPosition);
    To move the character up slowly, you can use the MC.MoveAndRotateTo(...) function. The character will "glide" 3 meters up.
    Code (CSharp):
    1. StartCoroutine(mMotionController.MoveAndRotateTo(_desiredPosition, Quaternion.identity, 1f, true, true, false));
    The MC.MoveAndRotateTo(...) function is a coroutine. So, you call it with the StartCoroutine(...) function. Internally, it uses AC.SetPosition(...), but does it over time.

    I hope that helps.
     
  50. Zante

    Zante

    Joined:
    Mar 29, 2008
    Posts:
    405
    I'm using UMA and need to regenerate the colliders for the body and feet at runtime (each time the character reloads). Before I jump into this, is there an obvious way to enable 'auto generation of bodyshapes' when using UMA?

    Edit Solved:
    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. using UMA;
    6. using UMA.CharacterSystem;
    7. using UMA.PoseTools;
    8. using com.ootii.Actors;
    9.  
    10. public class UMA_OOTII_GenerateBodyShapes : MonoBehaviour
    11. {
    12.     public ActorController actorController;
    13.     public bool actorControllerPresent;
    14.     private DynamicCharacterAvatar avatar;
    15.     private bool connected = false;
    16.  
    17.  
    18.     void OnEnable()
    19.     {
    20.         avatar = GetComponent<DynamicCharacterAvatar>();
    21.         avatar.CharacterCreated.AddListener(OnCreated);
    22.     }
    23.  
    24.     void OnDisable()
    25.     {
    26.         avatar.CharacterCreated.RemoveListener(OnCreated);
    27.     }
    28.  
    29.     public void OnCreated(UMAData data)
    30.     {
    31.         GenerateShapes();
    32.     }
    33.  
    34.  
    35.     // Start is called before the first frame update
    36.     void Start()
    37.     {
    38.         actorController = this.GetComponent<ActorController>();
    39.         if (actorController != null) { actorControllerPresent = true; }
    40.  
    41.     }
    42.  
    43.     public void GenerateShapes()
    44.     {
    45.         if (actorControllerPresent)
    46.         {
    47.             actorController.CreateBodyShapes();
    48.         }
    49.     }
    50. }
    51.  
     
    Last edited: Aug 26, 2020
    TeagansDad and Tryz like this.
unityunity