Search Unity

Bone Controller [RELEASED]

Discussion in 'Assets and Asset Store' started by Tryz, Feb 16, 2015.

  1. jdraper3

    jdraper3

    Joined:
    May 28, 2015
    Posts:
    117
    Any ideas on how to adjust a bone's position so that its collider is never colliding with anything else? Is that something that could be done with Bone Controller or would one of the ragdoll/animation assets like Puppetmaster be better suited for the task?
     
  2. Tryz

    Tryz

    Joined:
    Apr 22, 2013
    Posts:
    3,402
    It would require you to create custom motor. Doable, but a more complex task. The reason is that you can't just move bones. Imagine if your shin Bone just moved to the left...without your thigh bone.

    Instead uou have to manage the chain of Bo es... foot, shin, thigh, hips.... I do something like that with the Chain Drag motor for pony tails, tajls,etc. However, it doesn't get pushed by collisions.

    So yes, but there is some work for the motor builder to do.
     
  3. jdraper3

    jdraper3

    Joined:
    May 28, 2015
    Posts:
    117
    Thanks, that's kind of what I was thinking. I was actually already looking at the chain drag motor as a starting point since it had similar functionality. If I can get something working, I'll share it on here :)
     
  4. TeagansDad

    TeagansDad

    Joined:
    Nov 17, 2012
    Posts:
    957
    I'm noticing some weird behaviour with the Foot to Ground motor. When a character is walking next to a low railing (say less than 0.5m high), whichever foot is on the side nearest the railing will suddenly snap to the top of the railing when it is in the "top" position in the walk cycle. I've tried to get a screenshot of it, but it happens very quickly.

    Also, I've set up the same motor on a female character using the Female Animset Pro animations (basically copy and paste of the MAP_WalkRunPivot motion from the vault with the animations changed) and she walks fine normally but with the Foot to Ground motor active, whichever foot is in front is pulled to the ground a short distance ahead of her, which makes her knee look like it is bending inwards against the joint.

    What settings on the motor should I be looking at to fix these glitches?
     
  5. Tryz

    Tryz

    Joined:
    Apr 22, 2013
    Posts:
    3,402
    I'm doing the foot raycast from the heel position and up 0.5 meters.

    So, it's odd that the raycast would hit a rail off to the side. Can you confirm the rail colliders is off to the side too? Just want to make sure the colliders isn't unexpected.

    For the second one, there is an option for the leg to extend...meaning pull itself to the ground. If the leg is extended too much, I could see where the knee may look odd. I forget the option, but look for "extension" and there may be an enable flag or distance.

    I try to dynamically enable/disable the motor so the character doesn't duck-walk...meaning having the foot always forced to the ground even in an up cycle. I'm wondering if it is having a hard time with this animation.
     
  6. edFilms

    edFilms

    Joined:
    Aug 18, 2016
    Posts:
    5
    Hey Tim,

    I am super new to coding in Unity and I am trying to trigger a pose motor through a key press or mouse click. I know how to do it with certain objects in Unity, but I am not sure where to find the documentation on how your motors are found through a script.

    I am sure this is a super noob question, mostly I am just looking for any documentation you may have on how the motors are identified within unity scripts. Thanks so much. Wonderful plugin!
     
  7. Tryz

    Tryz

    Joined:
    Apr 22, 2013
    Posts:
    3,402
    Hi @edFilms ,

    I thought I had some examples in the User's Guide, but apparently not. I'll find time next week to get some.

    Until then, you really just need to grab the BoneController off your GameObject and then use the GetMotor() functions to grab the motor by name or type. From there, you can access properties directly.

    For example:

    Code (CSharp):
    1. BoneController lBC = gameObject.GetComponent<BoneController>();
    2. BoneControllerMotor lMotor = lBC.GetMotor("My Pose");
    3. lMotor.IsEnabled = true;
    You can see all the functions and properties available through your IDE's "Object Browser". That's a great resource for any object (not just the BC).

    Hopefully that gets you started. I'll add some examples to the documentation shortly.

    Also, check out the scene code in "Demos/Scenes" folder as well. You'll see some good examples. For example, the PoseMotorCode.cs file shows how you can set the weight of the motor like this:

    Code (CSharp):
    1.         GameObject lObject = GameObject.Find(rName);
    2.         if (lObject == null) { return; }
    3.  
    4.         BoneController lSkeleton = lObject.GetComponent<BoneController>();
    5.         if (lSkeleton == null) { return; }
    6.  
    7.         PoseMotor lMotor = lSkeleton.GetMotor<PoseMotor>();
    8.         if (lMotor == null) { return; }
    9.  
    10.         lMotor.Weight = rWeight;
     
  8. edFilms

    edFilms

    Joined:
    Aug 18, 2016
    Posts:
    5
     
    Tryz likes this.
  9. edFilms

    edFilms

    Joined:
    Aug 18, 2016
    Posts:
    5
    Hey Tim,

    I have made some progress based on your input. I managed to enable and disable a specific pose based on a key press. The results aren't quite what I want. I am assuming for a more natural blend I need to adjust the motors weight? I have tried this:


    BoneControllerMotor motor;

    // Use this for initialization
    void Start () {
    BoneController lBC = gameObject.GetComponent<BoneController>();
    motor = lBC.GetMotor<PoseMotor>("PoseJawOpen");
    motor.IsEnabled = true;
    motor.Weight = 1;
    }

    // Update is called once per frame
    void Update () {
    if (Input.GetKeyDown (KeyCode.A)) {
    motor.Weight = 0;
    }
    }
    }

    But it doesn't do anything in my tests. I am sorry if this is terribly obvious, but I am a total noob.

    Thank you in advance.

    Dan
     
  10. Tryz

    Tryz

    Joined:
    Apr 22, 2013
    Posts:
    3,402
    Hey @edFilms ,

    What you've got right now is an on-off switch and I think what you want is a dimmer. You'll probably want to put the logic in a loop so the weight value isn't just 0 or 1. Instead, you'll ramp up to 1 and down to 0 when the key is pressed.

    Coroutines are perfect for this, but so are a couple of simple state flags/variables.

    Hopefully this makes sense. If you need more direction, let me know.
     
  11. jrhee

    jrhee

    Joined:
    Dec 5, 2013
    Posts:
    74
    Just wondering, is there any way to have a motor's effect calculated between animation controller layers? For example, I have a base locomotion layer and an additional layer for full body overrides. I want my LookAt motor to override my locomotion animations but not my overrides. Worst case I can probably toggle the motor before and after override animations, but it's turning out to be tricky due to all the blending, interrupts, etc. that take place on the layer.
     
  12. edFilms

    edFilms

    Joined:
    Aug 18, 2016
    Posts:
    5
    Thank you, this is helpful. The only question I have now is with my current code I am unable to affect the weight of the joint. It doesn't change anyhting. Am I calling the wrong weight? Do I need to call the weight of the joint itself?

    Thanks again for the quick replies, you are awesome!

    Dan
     
  13. Tryz

    Tryz

    Joined:
    Apr 22, 2013
    Posts:
    3,402
    Unfortunately, I don't believe Unity allows that.

    The animations are processed at one time between Update and LateUpdate (see the "Internal animation update" node): https://docs.unity3d.com/Manual/ExecutionOrder.html

    The BC processes during LateUpdate since that's guaranteed to have the latest animation data.

    If you do work out a solution, I'd be curious how... I don't mind learning something new and it may be helpful to others too. :)
     
  14. Tryz

    Tryz

    Joined:
    Apr 22, 2013
    Posts:
    3,402
    No. You should just call it on the motor.

    In fact, in my demo scene for the Pose Motor I have a weight slider that does exactly what we're talking about:
    http://www.ootii.com/Unity/BoneController/Demo/Web.html

    Check out the 7th scene (Pose Motor). If you slide the slider at the mid-left, it blends my pose with the current animation. Take a look at the PoseMotor_code.cs file (I believe that's the name). That's the code you want to use... except yours will be in the loop or coroutine we discussed.
     
  15. edFilms

    edFilms

    Joined:
    Aug 18, 2016
    Posts:
    5
    Thanks Tim,

    I really appreciate your responsiveness and continued support, it means a lot to me.

    Wonderful work sir.

    Dan
     
    Tryz likes this.
  16. Kelvinhuang-0706

    Kelvinhuang-0706

    Joined:
    Aug 24, 2016
    Posts:
    2
    Hello everyOne~"bone chain drag motor" of bone controller complete didn't work with wind zone of unity ?
    Is it possible to receive the effect of wind?
    thk~~~~
     
  17. Tryz

    Tryz

    Joined:
    Apr 22, 2013
    Posts:
    3,402
    Hi @Kelvinhuang-0706 ,

    Correct. The Bone Chain Drag Motor is only effected by movement and gravity. However, if you have access to the wind zone's direction and strength, you could modify the motor (or create a new one) pretty easily.

    Just modify line 188. That's where the velocity of the bone is determined using gravity. Here, you could set the velocity based on gravity, the wind zone, or any other force.

    I hope that helps,
    Tim
     
  18. Kelvinhuang-0706

    Kelvinhuang-0706

    Joined:
    Aug 24, 2016
    Posts:
    2
    Dear @Tryz

    Thanks~I'll try to change velocity value~

    Kelvin
     
  19. biohazard9990

    biohazard9990

    Joined:
    Oct 18, 2016
    Posts:
    6
    Hi. So I was thinking, (perhaps this is a feature request) that the "look at motor" should be kind of like the motion list in the MC. Perhaps we could make a list of look at targets and set priorities. This way the character would look at the nearest target with the higher priority. Though it would also have to look for the closest target. But it would be a nice feature.
     
    Tryz likes this.
  20. Tryz

    Tryz

    Joined:
    Apr 22, 2013
    Posts:
    3,402
    That's sort of interesting.

    I do something similar with the sensors for my game. Basically, I know all the enemy that are near by. Then, I check which ones are visible using raycasts. Finally, I look at the one that's the closest.

    With your suggestions (which is good), I'm trying to think how you know what the list is. Is it just a set of fixed objects or does the list actually change as the character moves through the world?
     
  21. biohazard9990

    biohazard9990

    Joined:
    Oct 18, 2016
    Posts:
    6
    Yes. I was thinking like a list of certain targets (empty objects maybe) that people would define their own way and give a priority on the list. So those empty objects could be attached to items or something. But now I'm thinking that giving priority to "tags" would be better? IDK. Didn't think it through completely. It was just a spontaneous idea. Nice to see that u even considered it. lol Thanx.
     
    TeagansDad and Tryz like this.
  22. ayk

    ayk

    Joined:
    Nov 14, 2013
    Posts:
    58
    Question about creating bones from static meshes: Can the bones created in that way be manipulated in Skele to create new animations, or are they only usable with Bone Controller motors?
     
  23. Tryz

    Tryz

    Joined:
    Apr 22, 2013
    Posts:
    3,402
    I believe so, but I'm not a Skele expert.

    Bones are really just parented transforms. The BC understands that relationship and adds properties to support the bone motors. In this way, these "added bones" become part of the skeleton the BC controls.

    The image in the BC Guide (page 29) is a great example. The goblin's pony-tail is just a bunch of capsules parented together. The BC than uses motors to control it just as if they were part of the original model.

    I *THINK* Skele is able to manipulate transforms outside of a humanoid skeleton. In that case, he would be fine.
     
    TeagansDad likes this.
  24. ayk

    ayk

    Joined:
    Nov 14, 2013
    Posts:
    58
    Awesome. Thanks for the quick reply!
     
  25. ayk

    ayk

    Joined:
    Nov 14, 2013
    Posts:
    58
    Sorry to be a pain, but I did a bit more research and Skele operates exclusively on Skinned Mesh Renderers. So my new question is: When you create a skeleton from a static mesh, does it convert it into a skinned mesh renderer?

    I'm asking these weird questions because I'm investigating ways to create bones and animations in the Unity Editor without having to go out into Blender and do so. My objects are built in the same way as the turret in page 31 of the BC manual, and I'm looking for a way to create animations for them. Nothing too complicated, just basic walking, attacking, etc. And since the viewpoint will be fairly far off top-down/isometric perspective, they don't have to be very detailed/nuanced animations either.

    Hmm... perhaps I don't even need Skele at all? Do you think I could just use Bone Controller by itself to make simple animations?
     
  26. polytx

    polytx

    Joined:
    Oct 29, 2016
    Posts:
    2
    What is the performance overhead using this plugin vs using built in animation? I have a scene where I have potentially 100 different characters. I am also targeting the iPhone so every millisecond counts. Would you recommend this plugin for this particular use case?
     
  27. Anraksha

    Anraksha

    Joined:
    Dec 9, 2016
    Posts:
    10
    Hello

    I just want to know just two things if it's possible ^^ :


    1st question : for the "Look at" is there a possibility to smooth the going from left to right or the other way when the avatar look at something behind him for example :

    the avatar look an object behind him on the left but the object is moving and go on the right side of the avatar and then the avatar look at the right.
    Is there a parameter to use the fact that the head go from the left to the right because for the moment it look like an instant mirror action


    2nd question: can we instantiate dynamically all yours script with a script i'll create. because the problem is that the avatar i use is not present on the scene, it is loaded after the launch so in the scene there is no bones and if it's possible how to instantiate the joint or setting its values
    edit for the 2nd question : i somehow found a way to do that but i found something strange for the bones which i choose for the motor to stay in the motor, i need to focus on the Game object where i instantiate dynamically the bone controller (or not if i add a bone controller on the object but instantiate the motor with script that work too) to keep the bone in the motor the strange thing is that there are bones for like 1frame and after they vanish but if a had add some joint on the bones, the joint stay but i i keep focus on the game object where i instantiate the variables of the bone controller or where i add the bone controller dynamically the bones stay.
    I tested that on the "LookAt " controller.

    Maybe it's an error from me in my script (i'm still a beginner in C# and developpement on unity)


    Beside that I found that your footGround2BoneMotor have some probleme with the rig from MakeHuman (it has 4 bone for the leg 2 for the upper 2 for the lower).

    When you autoload the bones it choose the upperleg01 the lowerleg01 and the foot it create this result : Capture3 importante 2.png
    this picture has been taken at the limit of the moment where the leg will begin to move as you can see it's it move at approximately the half of the owerleg02. if we change the lowerleg01 for the lowerleg02 the detection is better but it give to the bone an : "OH MY GOD MY LEG IS BROKEN" look.

    Thanks for the time you will spend on the reading of my questions.
    Sorry for the bad english i'm still not bilingual
     
    Last edited: Dec 16, 2016
  28. wetcircuit

    wetcircuit

    Joined:
    Jul 17, 2012
    Posts:
    1,409
    Hi, I'm trying to use Playmaker to access/control the bone motors, but I'm not having much luck… I can't even find how to enable/disable individual motors… Ideally, I'd like to be able to set the weights, so the motors can ease in and out…. Anyone have advice with this?

    Also, some dumb newbie questions: is the idea to stack up a ton of motors and turn them on/off as needed (for instance, a dozen pose motors on the same figure), or is it to "better" to puppet limbs via dragging the IK targets around?
    And one more: the difference in Limb Reach and Swing At is that LimbReach is limited to 2 bones? How are you handling a "reach and grasp" combo with the FingerPose motor?
     
  29. Wilbert-Blom

    Wilbert-Blom

    Joined:
    Aug 13, 2011
    Posts:
    111
    How do I get to the Target Transform of a Look At Motor by C# script ?
    I can get the Motor with .GetMotor<LookAtMotor>() but I don't see a TargetTransform property
     
  30. hopeful

    hopeful

    Joined:
    Nov 20, 2013
    Posts:
    5,686
    Not sure if forum notifications dropped off, but it's been a while since @Tryz has visited here so I will casually drop this tag and see what happens. ;)
     
    wetcircuit likes this.
  31. Tryz

    Tryz

    Joined:
    Apr 22, 2013
    Posts:
    3,402
    Ugh... sorry guys.

    Apparently my notifications were disabled... again. I reset them all up and they are off again. :(

    I'm going through the thread now.

    Thanks @hopeful !
     
  32. Tryz

    Tryz

    Joined:
    Apr 22, 2013
    Posts:
    3,402
    Sorry for the massive delay. I never got notified there were messages. :(

    No, I don't convert it to a skinned mesh. That's because the skinned mesh really relies on skin weights that help determine which bone the vertex will move with. So, it's a lot more complicated than static meshes.

    It could to procedural ones. Meaning if you used math to rotate a bone from one position to another, you can certainly create motors for that. However, I don't think it would be good for key'd animations as I don't have any feature that will store the keys.
     
  33. Tryz

    Tryz

    Joined:
    Apr 22, 2013
    Posts:
    3,402
    Sorry for the 2 month delay. Certainly not the way I like to do things. :(

    The BC will only process bones if it sees there is a change. So, if you have 100 characters and you don't run a motor or no change is made, there will be no impact (maybe a tiny tiny bit). However, if all the characters are moving, the cost is really the function calls and the rotation of transforms. I'm not exactly sure how to quantify that for you, but it shouldn't be any more than normal animations.

    Unfortunately, I've never worked with an iPhone and mobile devices are just so different. I don't have a good answer for if it's good for your use case.
     
  34. Tryz

    Tryz

    Joined:
    Apr 22, 2013
    Posts:
    3,402
    Hi @Anraksha , sorry for the delay. My notifications stopped on this thread. :(

    The best thing to do is make sure you have limits setup. That will keep the head from turning more than 90 degrees or so. However, there's not a way to change the speed as it crosses behind. You could certainly customize a motor to do that, but the Look At motor doesn't have that ability.

    Yes. The best resource is to look at my BoneControllerEditor.cs file and the individual motor files. You'll find code about instantiating motors and setting values.

    The trickiest part is probably setting the root transform. But, if you just set "BoneController.RootTransform = x" it should setup everything just like the editor. Then, you can add motors.

    Start with the AddMotor() function on the BoneControllerEditor.cs file (line 994).

    Check out this video. I cover another model that has extra bones as well.
     
  35. Tryz

    Tryz

    Joined:
    Apr 22, 2013
    Posts:
    3,402
    Hi @wetcircuit , I'm sorry for the massive delay. My notifications for this thread stopped for some reason. :(

    I haven't used Playmaker much at all, but I believe it has "actions" for calling specific functions on objects. So, here's the logic you'd use in code. You'll have to translate that into Playmaker actions.

    Code (CSharp):
    1. BoneController lBC = gameObject.GetComponent<BoneController>();
    2. LookAtMotor lLookAt = lBC.GetMotor<LookAtMotor>();
    3. lLookAt.Weight = 0.5f;
    4. lLookAt.IsEnabled = true;
    Exactly. This way you can determine which motors you want and when. Pose motors probably have limited usability like this, but you can image that the LookAt and Foot motors can be enabled and disabled as needed.

    The Limb Reach is really for bending the 2-bone joints (arms and legs). It doesn't drag the spine. Swing At twists the spine very similar to LookAt, but won't be pulled by the arm/leg or target.

    I'd use and animation, Limb Reach motor, and the Finger motor together. So, let's say the object is on the ground. Your animation would have you bend over and reach forward. You turn on the Limb Reach and now it pulls the hand to the spot you want. Finally, you turn on the Finger motor to wrap around the object.

    Using the animation is much better since the character's whole body is kneeling and bending over. The IK parts are for fine-turning the exact grasp position.

    Again, sorry for the delay! :(
     
    wetcircuit likes this.
  36. Tryz

    Tryz

    Joined:
    Apr 22, 2013
    Posts:
    3,402
    Hi @Wilbert-Blom ,

    There is a TargetTransform you can set. It's a public variable on the LookAt Motor (line 26). So, your code would look like this:
    Code (CSharp):
    1. BoneController lBC = gameObject.GetComponent<BoneController>();
    2. LookAtMotor lLookAt = lBC.GetMotor<LookAtMotor>();
    3. lLookAt.TargetTransform = xxx;
    There's also a TargetPosition property for setting a Vector3, but the TargetTransform has priority.

    Please let me know if you still don't see it. That would be odd.
     
  37. Wilbert-Blom

    Wilbert-Blom

    Joined:
    Aug 13, 2011
    Posts:
    111
    Aaaah, found the problem:
    I used BoneControllerMotor as the type for the Motor instead of LookAtMotor. It works with GetMotor() but didn't give me the TargetPosition.
    http://avision.nl/files/LookAtMotor.gif

    Thanks for the help!
     
    Last edited: Jan 5, 2017
    hopeful and Tryz like this.
  38. LootlabGames

    LootlabGames

    Joined:
    Nov 21, 2014
    Posts:
    343
    Hello I was interested in the bone controller.
    I am wondering if it can help me with a few problems I'm having.

    I have animations I purchased that I am trying to use with the UMA models.
    When using polearm animations the hands are not always on the weapon.
    With the bone controller would I be able to have the hands adjust depending on what kind of polearm(thinner, thicker, etc.) and always stay on the weapon?

    Also I was thinking to try to use it for bows as well.
    When the fingers touch the bow string it will pull back the rigged bow, etc.
    I'm not sure if bone controller can do this though.
     
  39. Tryz

    Tryz

    Joined:
    Apr 22, 2013
    Posts:
    3,402
    Hi @katasteel

    Yes... sort of.

    Two handed weapons are tricky because one of the hands needs to "own" the polearm... lets call that the primary. If the polearm isn't a child of the primary, it won't move. Then the local position and rotation of the polearm needs to match the animation otherwise the secondary hand will be too far away.

    The BC wouldn't be used for the primary, but it could be used for the secondary (assuming it's close enough). The "Reach Motor" I have will pull the hand and arm to a specific spot. The "Finger Pose Motor" could then control how open and closed the fingers are (on both hands).

    Think of motors as fine-tuning the position where the animation do the rough large positioning.

    You could create a motor that would do this, but there's not one that exists.

    I do something similar in my Archery Motion Pack (without the BC). In this case, you're really just moving the "nock" back and bending the arms. I did it all in the asset.
     
    TeagansDad likes this.
  40. LootlabGames

    LootlabGames

    Joined:
    Nov 21, 2014
    Posts:
    343
    Expanding Bones list on BoneController freezes up Unity.
    Looking at Memory usage of Unity in Task Manager at this point reveals a steady incline in memory usage as well.

    I'm using the newest version of Unity.
     
  41. Tryz

    Tryz

    Joined:
    Apr 22, 2013
    Posts:
    3,402
    I'm not seeing that and I tried with 5 different characters. The max number of bones was 77.

    Here's what I did:
    1. Started a new Unity 5.5.1f1 project
    2. Downloaded and imported the latest BC
    3. Opened the LookAtMotor demo
    4. For each character, I clicked the "Show bones and limits"
    5. For each character, I unchecked "Only show selected bones"

    I also added a couple more characters just in case.

    If you want to send your FBX to tim@ootii.com, I'll take a look to see if it's something specific with your character.

    Any other assets in your project?
     
  42. LootlabGames

    LootlabGames

    Joined:
    Nov 21, 2014
    Posts:
    343
    It is the UMA 2(free asset) model.
    The fbx being used "Male_Unified.fbx".
    It reports 157 bones found.
    I will send you the FBX so you can take a look.
     
  43. Tryz

    Tryz

    Joined:
    Apr 22, 2013
    Posts:
    3,402
    I see what's happening...

    There are bones in the model that have no length. Meaning they have child transforms that are basically sitting with the parent (LeftCheekAdjust is an example).

    Since it has no magnitude, it has no bone direction.

    Since there is no bone direction, Unity is writing information messages to the console about the Quaternion.LookAt() function and that's what's eating the memory and killing performance.

    I handle when a bone has no children, but I expect that if there are child bones there is a distance...and a direction. I've updated the code to handle this case and now the messages aren't written.

    I'll send you the updated file in email.
     
    Last edited: Jan 31, 2017
    hopeful likes this.
  44. Astaelan1

    Astaelan1

    Joined:
    Sep 29, 2015
    Posts:
    192
    @Tryz Curious if you've had a chance to test with Morph3D characters? The MCS Male Lite is always free, but the MCS Male and Female are currently free on the store if you want to see about their bone setups.
    I'm currently looking at Bone Controller as MegaSplat has integrated with it to provide foot orientation against the tessellation displacement of the terrain and didn't run across anything about the MCS characters yet. Would be nice for this to just work seamlessly with them (they have a fair few extra bones as memory serves).

    Thanks for your time.
     
  45. Tryz

    Tryz

    Joined:
    Apr 22, 2013
    Posts:
    3,402
    Hey @Astaelan1 ,

    It does work with Morph3D characters. That's what I'm using for my game and I believe I use the female character in one or two of my videos.

     
  46. Astaelan1

    Astaelan1

    Joined:
    Sep 29, 2015
    Posts:
    192
    Ahh, that's great to hear, I didn't even notice the script on the character was M3D :)
    What I wouldn't give for the asset store to have a more formal system for "integrations" and "works with", save me a lot of questions heh.
     
    Tryz likes this.
  47. AliasPol

    AliasPol

    Joined:
    Jan 26, 2017
    Posts:
    12

    Hi. I have a litle problem. I need find all motors of searching type and function GetMotor only return first found type.

    Example:
    I have 2 LimbReachMotor and i want to set new tranform target for each via script. Is there posible way to get this?
     
  48. Tryz

    Tryz

    Joined:
    Apr 22, 2013
    Posts:
    3,402
    I'll add the function for the next update. For now, you can add this to the BoneController.cs file.

    Code (CSharp):
    1.         /// <summary>
    2.         /// Retrieves all the motors based on the motor's type.
    3.         /// </summary>
    4.         /// <returns>List of motors based on the specified type or null if none exist.</returns>
    5.         public virtual List<T> GetMotors<T>() where T : BoneControllerMotor
    6.         {
    7.             List<T> lMotors = null;
    8.  
    9.             Type lType = typeof(T);
    10.             for (int i = 0; i < Motors.Count; i++)
    11.             {
    12.                 if (Motors[i].GetType() == lType)
    13.                 {
    14.                     if (lMotors == null) { lMotors = new List<T>(); }
    15.                     lMotors.Add(Motors[i] as T);
    16.                 }
    17.             }
    18.  
    19.             return lMotors;
    20.         }
    21.  
    You would call it like this:

    Code (CSharp):
    1. List<LimbReachMotor> lMotors = lBoneController.GetMotors<LimbReachMotor>();
    2. if (lMotors != null)
    3. {
    4.     // Add your code
    5. }
     
  49. AliasPol

    AliasPol

    Joined:
    Jan 26, 2017
    Posts:
    12
    Thanks for your fast answer.

    I have one more problem with Foot 2 Ground Motor:
    - when my test cube is going up foot of object is going up with cube but when cube go down leg stay in air.
    What may couse this problem?

    And i have a question:
    - can rotate motor dont rotate object automatical? I wanna rottate bone when press for example
    - "a" for rotate left and "d" for rotate right.
     
  50. Tryz

    Tryz

    Joined:
    Apr 22, 2013
    Posts:
    3,402
    That's the way animations and foot IK works. Your animation will set the leg position and then IK comes in an adjusts it. The next frame the animation sets the leg position and then IK comes in and adjusts it. And so on.

    It can, but you need to control when that happens. For example, in your code you would enable/disable the motor or change the motor weight property based on the input.