Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Ultimate Rope Editor - New powerful rope physics for Unity3D [RELEASED]

Discussion in 'Assets and Asset Store' started by UGTools, Feb 11, 2013.

  1. UGTools

    UGTools

    Joined:
    Oct 10, 2012
    Posts:
    738
    Hello Seith!

    Indeed, the plugin needs to move these bones to the top of the hierarchy because otherwise their transforms would still be linked to the character and instead of swinging around when the character turns around for instance, they would remain fixed to it.
    One solution to the first problem would be to do this on start at runtime, but that wouldn't fix the Mechanim issue. I haven't played with Mechanim myself so I don't know about its limitations, but do these chain bones need to be setup using Mechanim? I mean, if they are part of the rope system I would keep them out, otherwise I'm pretty sure both would be messing with the transform. And if you want to use the rope system for the physics, there is no point in having them in Mechanim anyway... :)
     
  2. Seith

    Seith

    Joined:
    Nov 3, 2012
    Posts:
    755
    Thank you for your quick reply! :)

    So I managed to get rid of the Mecanim complains by indeed removing the hood joints from the character's Avatar (unchecked "Keep Additional Joints" in the Rig tab of the FBX import section).

    Now for the prefab-breaking issue; do you mean to simply create the rope at launch-time (in an Awake function)? That sounds good. In that case is there some documentation about accessing the UltimateRope fields and variables by scripting?
     
  3. UGTools

    UGTools

    Joined:
    Oct 10, 2012
    Posts:
    738
    No problem, that's why I am here for :)

    I'd play with the rope and do the finetuning normally (breaking your prefab), and when you're happy with the parameters press "Reset Rope" to delete the rope nodes and bring the bones back to their original hierarchy. The rope component will still be there.though, with all the parameters already set.
    And at runtime to create the rope you simply need to call rope.RegenerateRope() in the Start function (not the awake, because the rope uses its own Awake and the script execution order could cause problems).
    Hopefully that will do what you're asking for. Tell me if it works!

     
  4. Seith

    Seith

    Joined:
    Nov 3, 2012
    Posts:
    755
    Mmh. I folowed those steps but when I click on "Reset rope" nothing happens; the joints do not go back to their original place in the hierarchy.

    Update: Oh I guess you meant to say to click on "Delete rope" in your message. Which would make sense. So that part works.

    Now when I call rope.RegenerateRope() in the Start function I get an error message:

    Assets/Scripts/Player/PlayerControl.cs(266,17): error CS0103: The name `rope' does not exist in the current context

    I tried:

    playerTransform.GetComponent<UltimateRope>().RegenerateRope();

    and

    UltimateRope.RegenerateRope();

    But that didn't work either...
     
  5. UGTools

    UGTools

    Joined:
    Oct 10, 2012
    Posts:
    738
    Yes sorry, I meant "Delete Rope" indeed :)
    The RegenerateRope must be called on the object that has the UltimateRope component. My guess is that your character doesn't have it, but rather an object called Rope in the top of the hierarchy somewhere in the scene.
    One suggestion could be adding to PlayerControl a public property like:

    public UltimateRope HatRope;

    Then assign it on the inspector, choosing the rope node from the scene. And on Start() add the following line (again, on PlayerControl.cs):

    if(HatRope != null) HatRope.RegenerateRope();

     
  6. Seith

    Seith

    Joined:
    Nov 3, 2012
    Posts:
    755
    Ok, so I followed your instructions but I get this error message:

    Assets/Scripts/Player/PlayerControl.cs(269,34): error CS1061: Type `UltimateRope' does not contain a definition for `RegenerateRope' and no extension method `RegenerateRope' of type `UltimateRope' could be found (are you missing a using directive or an assembly reference?)
     
  7. UGTools

    UGTools

    Joined:
    Oct 10, 2012
    Posts:
    738
    Sorry I must be missing a dose of coffee or something. It's Regenerate() :)

     
  8. Seith

    Seith

    Joined:
    Nov 3, 2012
    Posts:
    755
    Hey no problem... :)

    So I just use: playerTransform.GetComponent<UltimateRope>().Regenerate(); in my Start function which now works but still the rope is not live (the joints don't get taken out of the hierarchy). It only becomes live if I click on "Reset rope" during play time.

    So basically I'm looking for a way to accomplish the same thing as clicking on that button, but via scripting. Are you absolutely certain Regenerate() is the right function?
     
  9. UGTools

    UGTools

    Joined:
    Oct 10, 2012
    Posts:
    738
    Yes, I've set up the same scenario in my machine with the girl model in the webplayer demo and it works ok. What "Reset Rope" internally does is calling Regenerate().
    I see you are still getting the UltimateRope component from the player node, but you say it now works. Did you delete the original rope component and added it to the player node? The bones are re-parented to the rope node, and if now your rope node is the player itself it won't work because it still will be part of the player hierarchy.

    My suggestion:
    1-Rope GameObject is on top of hierarchy, a GameObject with no parent.
    2-Add a public reference to the rope to the PlayerControl class (my guess is it is a component added to the main character). Use this:
    public UltimateRope HatRope.
    3-Assign the rope in 1 to the new parameter added in 2 through the inspector.
    4-Add the following line to PlayerControl.cs (in the Start method):
    HatRope.Regenerate()


     
  10. Seith

    Seith

    Joined:
    Nov 3, 2012
    Posts:
    755
    Just to give you a better idea of my player prefab:



    The UltimateRope script is assigned to Player_prefab. The hood joints are in the hierarchy within Bip01 (the character's skeleton). The "real" character model is "mouse" (in the Model group).

    And there is absolutely no rope object (or simply objects called "Rope") anywhere in the scene. Maybe if you can reproduce that hierarchy with your character and see if it still works on your side...

    Note: PlayerTransform in my script refers to the Player_prefab transform.
     
    Last edited: Jun 11, 2013
  11. UGTools

    UGTools

    Joined:
    Oct 10, 2012
    Posts:
    738
    Ah ok. Normally you would create the rope by using GameObject->Create Other->Ultimate Game Tools->Rope, which creates a rope gameobject for you. I guess you've added the Ultimate Rope component to the player prefab manually.
    What you want to do is create a rope this way (thus, creating a separate gameobject for the rope), and then add the reference to the PlayerControl as explained in the previous post. What happens if you have the rope on the character is the free bones get reparented to the node that has the rope, but in your case this node is the character itself and if it moves, the bones will move not because of the physics, but because of the parenting. So the end result is they will still be fixed to the character and not swing at all.



     
  12. Seith

    Seith

    Joined:
    Nov 3, 2012
    Posts:
    755
    Here's what I did:

    - Got rid of any existing UltimateRope component.

    - Created a rope by going to GameObject->Create Other->Ultimate Game Tools->Rope.

    - Added public UltimateRope HatRope to my PlayerControl script (which is attached to Player_prefab).

    - Assigned the Rope object to HatRope.

    - Added HatRope.Regenerate() to the Start() function of my PlayerControl script.


    But it still doesn't work unfortunately. Did I miss something?
     
  13. UGTools

    UGTools

    Joined:
    Oct 10, 2012
    Posts:
    738
    Which part doesn't work?
    It should:
    -Create the rope like before but:
    -Now the free bones should hang from the rope node, which itself should be a root node (and not hang from any other scene node)

     
  14. Seith

    Seith

    Joined:
    Nov 3, 2012
    Posts:
    755
    I mean the joints are not getting reassigned to the Rope node (which is at root level of the world, not parented to anything); they stay in their original place within the character's skeleton hierarchy.

    Again what really puzzles me is if I click on "Reset rope" during gameplay then everything happens as expected: the rope joints are taken out of their hierarchy and get reassigned to the Rope object.

    Hence my previous question; are you certain that by clicking the "Reset rope" button nothing else happens besides calling "Regenerate()"? If you are, then it must be a time issue. Like the rope system doesn't have time to do something it should, which gets effective only after the game has really started...
     
  15. Seith

    Seith

    Joined:
    Nov 3, 2012
    Posts:
    755
    Ok, it's not a time issue; I've used a switch to call Regenerate() once at the start of my Update() function (so after the Awake() and Start() functions have run) and still no dice. I really don't understand.
     
  16. UGTools

    UGTools

    Joined:
    Oct 10, 2012
    Posts:
    738
    Yes, calling Regenerate() should be enough, I've tested it myself with the ponytail character. I'm preparing a .zip so you can take a look at it and see if there is something different in your scene.
    Are you sure you are calling it in the Start (and not Awake) part of the script? and that it is called at all? To see if the bones made it into the rope you can check if at runtime they have the configurable joint and rigidbody components (which at edit time they shouldn't have, if you pressed "Delete Rope").

     
  17. UGTools

    UGTools

    Joined:
    Oct 10, 2012
    Posts:
    738
    OK, and does this add the rigidbody and configurable joint components to the bones? I'm trying to figure out if the only thing that's missing is the re-parenting or if the rope isn't generated at all.

     
  18. Seith

    Seith

    Joined:
    Nov 3, 2012
    Posts:
    755
    I triple-checked that Regenerate() is indeed called in the Start function (not the Awake one).

    And to answer your question: no they don't even get the configurable joint and rigidbody components. The rope isn't generated at all.
     
  19. Mr-Logan

    Mr-Logan

    Joined:
    Apr 13, 2006
    Posts:
    455
    I may be doing it differently than you would, but my result here is that the harpoon doesn't move, despite the rope tugging. it's as though the forces on the harpoon don't affect it's parent, the ship.

    I tried with a simple cube, with a rigidbody component attached, same result, the harpoon doesn't seem to affect it's parent's rigidbody, if it is a child.
     
  20. UGTools

    UGTools

    Joined:
    Oct 10, 2012
    Posts:
    738
    Does the status on the rope panel (Ultimate Rope, on top) say anything after pressing play?

     
  21. UGTools

    UGTools

    Joined:
    Oct 10, 2012
    Posts:
    738
    I would have to check if a child can make its parent move, but I just had an idea. Remember what we tried with forcing the harpoons positions? (Post link).
    Try the following:
    -Change the priority of the script that forces the harpoon position, to a priority so that it executes before the default one (-100 for example). You can access this panel through edit->project settings->script execution order.
    -Force the position inside the FixedUpdate() instead of the LateUpdate(). Only do this if the harpoon hit the boat, of course.

    Tell me if it works because I'm just guessing and don't have any similar workspace to test this :)


     
  22. Seith

    Seith

    Joined:
    Nov 3, 2012
    Posts:
    755
    Nope, it just says "Rope generated in ..." with the time it took when I first setup the rope (before I clicked on "Delete rope"). Interestingly, after pressing play the number (with a gazillion decimal) doesn't change at all, indicating that the rope in fact doesn't get created. But if I click on "Reset rope" then the number changes, indicating that this time the rope actually gets created.
     
  23. UGTools

    UGTools

    Joined:
    Oct 10, 2012
    Posts:
    738
    I know this is super obvious but is the HatRope property assigned in the inspector? And is it assigned with the correct rope? If you've got a null check before the Regenerate() and the HatRope isn't assigned it may behave just like you're saying.
    I've got a sample project set up to show it to you, if you give me an e-mail I can send it so you can check out what's going wrong.

     
  24. Seith

    Seith

    Joined:
    Nov 3, 2012
    Posts:
    755
    It is, yes. And I actually removed the Null check, so if the rope node weren't found it would actually trigger an error. You can send me the sample project here: seith [at] seithcg.com.

    I really want to get this working, as I really like the result when I manually trigger the rope creation... :)
     
  25. Mr-Logan

    Mr-Logan

    Joined:
    Apr 13, 2006
    Posts:
    455



    It works until the pressure on the rope becomes too great, then it spasms out, up until that point however this seems to be the best solution.
    Do you know if it is possible to "read" how much force is on the rope, so I could perhaps just slow it down when it gets too bad?

    Also I'd be glad to send you my setup, if you want to play around with it
     
  26. Seith

    Seith

    Joined:
    Nov 3, 2012
    Posts:
    755
    @UGTools: Thanks for the project sample! It helped me to understand better how the rope's supposed to work. My problem is fixed at last! :) It was all my fault; I had setup a trap for myself in another script that disabled the PlayerControl script at start depending on which scene was loaded. It was a vicious little thing and the lesson is learned.

    But now that it's fixed I have to say everything works beautifully. Thank you so much for your help and patience! I will definitely use your dynamic system for "Ghost of a Tale"... :)
     
  27. UGTools

    UGTools

    Joined:
    Oct 10, 2012
    Posts:
    738
    Hello Seith!

    I'm glad it worked! I was having a hard time trying to figure out what could be going wrong.
    By the way, I took a look at your WIP videos and have to say they look gorgeous! I wish you all the best for "Ghost of a Tale", if you need any more help just ask me :)

     
  28. UGTools

    UGTools

    Joined:
    Oct 10, 2012
    Posts:
    738
    So at least we've come closer to a working solution :)
    Unfortunately there is no API access in Unity to know what tension is being applied to a given joint, but I've had a similar situation in one of my projects and what I did was compare the distance between the 2 gameobjects: rope start and the end (in your case the harpoon), to the actual rope length between the start and the end. If the second number is smaller that means the rope is in tension and here you should stop retracting the rope.

    So, compare:

    Code (csharp):
    1. float fNodeDistance = Vector3.Distance(rope.RopeStart.transform.position, harpoon.transform.position);
    to:

    Code (csharp):
    1. float fHarpoonRopeLength = rope.RopeNodes[0].fLength + rope.m_fCurrentExtension;
    If fHarpoonRopeLength is smaller than fNodeDistance, you should stop pulling until it becomes bigger again.
    The second line of code uses undocumented scripting properties but they are still accesible to you.
    This should work if you've only got 1 rope node (just a RopeStart and the SegmentEnd being the harpoon), which is the impression I got from the demo. If you've got more than 1 segment tell me because the scripting would vary a little bit.

    Try that and tell me if it works :)

     
  29. Mr-Logan

    Mr-Logan

    Joined:
    Apr 13, 2006
    Posts:
    455
    Your thinking seems sound, however I think there's an error somewhere in the code you provided

    $6Xb0wVd.png

    If you see the values on the right hand side, the marked on is the latest, rope.RopeNodes[0].fLength stayed at 16 from start to finish, which means it would likely never go below the value of fNodeDistance.


    EDIT

    I just tried exchanging the ' + ' with a ' * ' and the result seems wrong, that is, the length at one point says +100, while I can clearly see it is below 100, probably even bellow 50, however when it really counted, that is, when the rope was about to get stretched the value was below the value of fNodeDistance.


    EDITEDIT
    Nah, it still isn't working quite as it should, even with the ' * ' it's still glidding at the very end.

     
    Last edited: Jun 12, 2013
  30. UGTools

    UGTools

    Joined:
    Oct 10, 2012
    Posts:
    738
    Can you give me a screenshot of the rope parameters?
     
  31. Mr-Logan

    Mr-Logan

    Joined:
    Apr 13, 2006
    Posts:
    455


    Certainly

    $lgt78d5.png
     
  32. UGTools

    UGTools

    Joined:
    Oct 10, 2012
    Posts:
    738
    I see, you have a coil which internally adds an additional node.
    So your code would be:

    Code (csharp):
    1. float fNodeDistance = Vector3.Distance(rope.RopeStart.transform.position, harpoon.transform.position);
    2. float fHarpoonRopeLength = rope.RopeNodes[rope.RopeNodes.Count - 1].fLength + rope.m_fCurrentExtension;
    3.  
     
  33. Mr-Logan

    Mr-Logan

    Joined:
    Apr 13, 2006
    Posts:
    455
    Ah, I thought that was self evident, sorry for not mentioning that =)

    And that solution works perfectly, thanks for taking the time to help me this much with it =)
     
  34. UGTools

    UGTools

    Joined:
    Oct 10, 2012
    Posts:
    738
    Woohooo! :)

     
  35. UGTools

    UGTools

    Joined:
    Oct 10, 2012
    Posts:
    738
    I've sent the update that removes the annoying deprecated messages on Unity 4.x and also the small bug that prints error messages when an extensible rope is created without a coil. It should be available really soon.
     
  36. UGTools

    UGTools

    Joined:
    Oct 10, 2012
    Posts:
    738
    Wow! it took less than I thought. It's already available but somehow I forgot to update the release notes. So the release notes are still the same as 1.10 but the package is correctly updated :)
     
  37. johnnydj

    johnnydj

    Joined:
    Apr 20, 2012
    Posts:
    211
    I'm banging my head against this for about 5 hours now....
    Can you explain somehow, or make a quick simple tutorial how to achieve something like this?


    $stock-photo-wooden-signpost-hanged-with-ropes-109903652.jpg
     
  38. UGTools

    UGTools

    Joined:
    Oct 10, 2012
    Posts:
    738
    Hi johnny!

    You need 2 separate ropes for the left side and the right side. Make them so that the rope start (the top) is just a simple empty GameObject and the rope end is a GameObject with a rigidbody (the kinematic parameter unchecked) and a box collider attached. Scale the box colliders so that each one takes more or less half of the wood sign, but they shouldn't intersect each other.
    Now, add a rigidbody and a box collider to the wood sign as well.
    As last step, add a fixedjoint to the left rope end and the right rope end, and connect them both to the wood sign.

    This should do what you have in your screenshot. Basically it's more or less the same setup that Mr Logan had.


     
  39. johnnydj

    johnnydj

    Joined:
    Apr 20, 2012
    Posts:
    211
    Thanks a lot.
    Worked out perfectly!
     
  40. Mr-Logan

    Mr-Logan

    Joined:
    Apr 13, 2006
    Posts:
    455
    Haha I'm back! :D

    I am now trying to make a rope on the fly, the rope is the one for the harpoon gun from earlier.
    I want it to reload by spawning a new harpoon and tying the rope to the end of it.

    This is what I have so far, it doesn't work but I think I'm close

    Code (csharp):
    1. void NewHarpoon(){
    2.     harpoonGO = (GameObject)Instantiate(harpoonPrefab, harpoonSpawnTrans.position, harpoonSpawnTrans.rotation);
    3.     harpoonGO.GetComponent<HarpoonHandler>().harpoonSpawnTrans = harpoonSpawnTrans;
    4.    
    5.     UltimateRope.RopeNode ropeNode = rope.RopeNodes[rope.RopeNodes.Count - 1];
    6.    
    7.     UltimateRope.RopeNode ropeNode2 = rope.RopeNodes[rope.RopeNodes.Count - 1];
    8.     int stuff = ropeNode2.segmentLinks.Length;
    9.     print(stuff);
    10.     ropeNode.segmentLinks = new GameObject[1];
    11.     ropeNode.segmentLinks[stuff] = harpoonGO;
    12.     rope.Regenerate(true);
    13. }
     
  41. Mr-Logan

    Mr-Logan

    Joined:
    Apr 13, 2006
    Posts:
    455
    It still has the coil, which is why the "end" needs to be placed like in a segment (as far as I know).

    Also what is going wrong is that the rope spasms out.
     
  42. Mr-Logan

    Mr-Logan

    Joined:
    Apr 13, 2006
    Posts:
    455
    I just discovered that I thought it had placed the harpoon in the "segment end" as it should, however it just didn't clear that field when I deleted the harpoon gameobject.
    So clearly I'm doing it more wrong than I thought, heh. Any help would be greatly appreciated. =)
     
  43. Mr-Logan

    Mr-Logan

    Joined:
    Apr 13, 2006
    Posts:
    455
    Oh, I found it.

    Code (csharp):
    1. ropeNode.goNode = harpoonGO;
    Way to over complicate it for my self.

    It's a little confusing though that the names do not match with the names in the editor.
     
  44. Mr-Logan

    Mr-Logan

    Joined:
    Apr 13, 2006
    Posts:
    455
    Can I force the rope to snap (break) on the middle?
     
  45. laurent-clave

    laurent-clave

    Joined:
    Jul 18, 2011
    Posts:
    280
    Hi,

    I'm trying to make a fishing game
    $625029rodprint.jpg

    I wish we could throw the line, so that the line is free, and then bring

    Is that you can pass a linefrom point A to point F?
    Is that I know the force applied at point E to bend the fishing rod?
     
    Last edited: Jun 18, 2013
  46. Hwaus

    Hwaus

    Joined:
    Mar 21, 2013
    Posts:
    13
    Could not find any documentation or tutorial on how to set up the rope in a scene; however several sample scenes that do not make very much sense on their own. Rope with coil goes haywire after 2 seconds of extension. Customizing any of the values in the ultimate rope script causes crashes, particularly extendable length, which crashes unity if you extend the rope to approx. 60. This asset is not very practical because it uses up a lot of CPU. Between the rope going haywire, the crashes, and the lack of rope length, quite disappointed. Will post supporting video as soon as it is done processing. Please recommend fixes or workarounds, thanks.
     
    Last edited: Jun 19, 2013
  47. Mr-Logan

    Mr-Logan

    Joined:
    Apr 13, 2006
    Posts:
    455
    Have you tried this page?
    http://www.ultimategametools.com/products/rope_editor/help
     
  48. Hwaus

    Hwaus

    Joined:
    Mar 21, 2013
    Posts:
    13
  49. UGTools

    UGTools

    Joined:
    Oct 10, 2012
    Posts:
    738
    What the hell??!?! I just visited this thread because I didn't receive any notifications for a while (it's supposed to send me an e-mail as soon as there's a new post) and saw the new messages. Sorry guys!
     
  50. UGTools

    UGTools

    Joined:
    Oct 10, 2012
    Posts:
    738
    Did you manage to do this? at which point are you stuck?