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

Rope Script V2 now availiable - 8/08/10

Discussion in 'Made With Unity' started by reveriejake, Nov 19, 2009.

?

Should I continue to support this script

  1. Yes I need this script and appreciate your support!

    94.0%
  2. I think its fine how it is!

    3.5%
  3. I know enough about programming to fix it myself!

    2.5%
  1. Toad

    Toad

    Joined:
    Aug 14, 2010
    Posts:
    297
    How's the next release of the Rope Script going Jake?
     
  2. reveriejake

    reveriejake

    Joined:
    Jul 8, 2007
    Posts:
    815
    Hey hopefully I will be able to get it done soon. But as ive said in previous posts and on my website, I am in the middle of moving and I have also been working a lot.

    I do have good news though, I have been working on the script over the past few days and this attempt seems to be working a lot smoother then the previous versions. I have already got a good core of the script done!

    In the mean-time, I released a concept script to my website that goes on the grapple idea. Keep in mind though that the grapple script is only a concept and isn't really intended to be fully functional. If you have a good programmer, anyone can pick up that script from online and do whatever they want with it!

    Hope to give you guys something soon. I know I have been promising it but hopefully soon!

    PS: New code has ~350 lines of code compared to ~900 lines to do the same thing in the previous version.

    Jake
     
    Last edited: Dec 16, 2010
  3. reveriejake

    reveriejake

    Joined:
    Jul 8, 2007
    Posts:
    815
    Some people will enjoy this new feature. It clamps the ends of the rope to help prevent the rope from breaking when it is stretched. There is a mass of 50 (40 higher than your ever supposed to see) attached to the end of the rope in the video.

    http://vimeo.com/17914776
     
  4. bigkahuna

    bigkahuna

    Joined:
    Apr 30, 2006
    Posts:
    5,435
    That will be useful, cool!
     
  5. reveriejake

    reveriejake

    Joined:
    Jul 8, 2007
    Posts:
    815
    Yeah I think so. The demo video didnt really show it off too well because all the joints weigh the same and it had a weight with a mass of 50 as I said which is way higher than your supposed to have on there. But the idea is that it should allow those who want to "Pull" on the end of the rope to drag something to do so without destroying the rope.

    Also, I will make the function available on my site probably tonight for anyone who might be interested in a Vector3 clamping method that is a little better than Unity's Vector3.ClampMagnitude() method (My version allows you to make your clamped vector Kinematic).
     
  6. reveriejake

    reveriejake

    Joined:
    Jul 8, 2007
    Posts:
    815
    Hey guys/gals! I was originally planing to release the new rope scripts on christmas day but seeing that I only have internet on my phone until they hook it up Sunday, its going to have to wait until then. I will post here and my site once the script is online Sunday!

    Hope everyone has happy holidays and I look forword to continue being part of this wonderful community in 2011!

    Jake
     
    Last edited: Dec 26, 2010
  7. reveriejake

    reveriejake

    Joined:
    Jul 8, 2007
    Posts:
    815

    Attached Files:

    Last edited: Jan 2, 2013
  8. Toad

    Toad

    Joined:
    Aug 14, 2010
    Posts:
    297
    Cheers Jake! Downloading now...

    Merry Christmas!!
     
  9. immFX

    immFX

    Joined:
    Mar 20, 2010
    Posts:
    109
    Merry Christmas Jake!
    Thank you for your constant giving to the community.
    Will report on the new rope script as soon as I try it.
     
  10. EmadGh

    EmadGh

    Joined:
    Jun 10, 2009
    Posts:
    144
    Wow thank you. and I think you should change the name of topic.
     
  11. reveriejake

    reveriejake

    Joined:
    Jul 8, 2007
    Posts:
    815
    I keep trying.. but no success with the new forum system :(

    Let me know if you know how!

    Jake
     
  12. stephnx

    stephnx

    Joined:
    Mar 18, 2009
    Posts:
    7
    Amazing script! Thank you!
     
  13. EmadGh

    EmadGh

    Joined:
    Jun 10, 2009
    Posts:
    144
    Go to the first post. Press Edit. then Go Advanced. there you can change topic name(title).:)
     
  14. reveriejake

    reveriejake

    Joined:
    Jul 8, 2007
    Posts:
    815
    @emadgh:
    I tried that awhile back but it didnt seem to work... :( It just changes the title topic for the first post. I did some research and apparently I have to send a PM to a forum moderator which I did so hopefully it will be changed soon!

    TO EVERYONE ELSE:
    I posted the package to Unity's new Asset Store tonight (Free Price) and hopefully it will be approved soon. The only thing I ask is if anyone downloads it from the asset store and finds the script to be useful in your game, go to my site and DONATE! This script is no easy task to complete with just one person and donations are always a good feeling and feed my drive to complete the projects I start.

    Thanks VERY MUCH for all the support I have gotten so far!

    Jake
     
    Last edited: Dec 27, 2010
  15. _Adriaan

    _Adriaan

    Joined:
    Nov 12, 2009
    Posts:
    463
    Hey Jake,

    I've been using your script a bit and it sure is easy as hell!! I've just got this one problem you might be able to help me with:

    I have 2 rigidbodies that can each move that are the ends of the rope. Although gravity is turned on for each detail, it doesn't seem to apply it fully... This is what you get even when the rigidbodies don't move:



    Any ideas on how to solve it and make sure all the details work like a proper rope with gravity?

    (perhaps we should continue our conversation over the message system, if that works better for you?)
     
  16. reveriejake

    reveriejake

    Joined:
    Jul 8, 2007
    Posts:
    815
    I need more information on this issue.

    The ends of the ropes no longer have colliders either because of previous issues, so if its colliders your talking about, you need to add them manually.

    I also dont see any images if you attached some so please PM me with more info.

    Sorry,
    Jake
     
  17. reveriejake

    reveriejake

    Joined:
    Jul 8, 2007
    Posts:
    815


    Also, you might want to try and play around with the joint settings. The previous version of the rope script had some issue where they kind of ignored the settings (Dont know why but they had little effect). The current version seems to be sensitive to the settings.

    Please let me know what you found if you find a solution!

    Jake
     
  18. immFX

    immFX

    Joined:
    Mar 20, 2010
    Posts:
    109
    Jake, you mention about a "fully functioning 'mesh tube' rope type" (a long awaited feature for me ;) ), yet I see no such prefab (or example scene) in the new package.

    Also, have you removed the (most useful) pull-rope, push-rope features from the new script?
     
    Last edited: Dec 28, 2010
  19. _Adriaan

    _Adriaan

    Joined:
    Nov 12, 2009
    Posts:
    463
    Jake, I fixed it and it's f*cking brilliant, I tell you! The latest version of your script, plus a lot of playing with the settings totally solved the problem!

    Love you man. I'm very looking forward to the runtime adding/removing segments, as it will be exactly the thing I need!

    You'll definitely hear again from me :D
     
  20. reveriejake

    reveriejake

    Joined:
    Jul 8, 2007
    Posts:
    815

    Actually the mesh tube renderer is included and it works beautifully. All you got to do to set it up is set the rope type to "Mesh" (The setting that is set to "Line" by default) and it should work fine!

    As for the push-pull script I will be publishing that soon as a free add-on and I will post here when I do that. It will be used like the new attach objects script where you just drag it into the object like a component.

    Sorry for any confusion!
    Jake
     
  21. immFX

    immFX

    Joined:
    Mar 20, 2010
    Posts:
    109
    I made a donation - the least I could do - and I would recommend that everyone else using Jake's script do the same.
     
  22. reveriejake

    reveriejake

    Joined:
    Jul 8, 2007
    Posts:
    815
    Hey thanks! I am assuming you found the tube render feature?

    Jake
     
  23. immFX

    immFX

    Joined:
    Mar 20, 2010
    Posts:
    109
    Yes, I was looking for a rope prefab, that's why I missed it. Thanks.

    Now, if I set "Rope Type" to Mesh and set the Rope Material, the texture seems to be stretched along the length of the rope (instead of vertically).
     
  24. reveriejake

    reveriejake

    Joined:
    Jul 8, 2007
    Posts:
    815
    It does? I thought I had fixed that... Must have grabbed an older version of the tube render script. I will take a look at it later on tonight!

    Thanks
     
  25. reveriejake

    reveriejake

    Joined:
    Jul 8, 2007
    Posts:
    815
    @immFX:
    Hey, to fix this problem set the texture tiling to something like "x=1, y=40" (Using the rope texture included... Other textures might vary).

    @ Adriaan:
    I am adding tooltips to the editor so you can learn a bit more about what is going on by hovering your mouse over it as you suggested. But I would like to know which areas of the editor are confusing and which ones are clear so I know which controls to put more detail into!
     
    Last edited: Jan 2, 2011
  26. xadhoom

    xadhoom

    Joined:
    Sep 2, 2010
    Posts:
    91
    Hi Jake,

    Congratulation for this major release step! :)

    I´ve a few remarks about this release. Although everything is OS to fix it myself maybe you already adressed these things:
    1. The rope pivot does not move along with the rope center when set to mesh.
    2. The mesh rope is hardly visible in editor mode, any chance to calculate the resulting mesh already on editor time?
    3. The rope corners could be improved if you use first level subdivision for line renderer and mesh (optionally?).
    4. The end segments suffer rotation artifacts probably because you don´t use colliders here (mesh and linerenderer).
    5. Could you please put the runtime data (_JointContainer, TUBE) as children of each rope to keep the hierarchy clean? This would be very helpful for debugging.
    6. Do you know any way to alter the sleep property of colliders to improve runtime performance if nothing moves?

    I´m unsure how you plan the upcoming implementation with your new design. Let me know if it makes sense to provide you patches directly instead of just complaining ;-)

    xad

    PS: In one of my snippets I proposed a way to calculate uv coordinates for the mesh rope to allow flexible tiling in u and v direction.
     
  27. mattirwin

    mattirwin

    Joined:
    Jan 3, 2011
    Posts:
    13
    Jake,

    Thanks so much for this amazing script. The new procedural mesh tube rope was exactly what I was looking for. Using it I can quickly tweak the parameters and test until I get the right effect. A small donation is on the way from me, thanks.

    --Matt
     
  28. reveriejake

    reveriejake

    Joined:
    Jul 8, 2007
    Posts:
    815
    Thanks, I will try to address some of these issues but I cannot guarantee that they will all be addressed. I have again started working on other projects and still need to provide the community with the push/pull script for the rope to at least get it back up to par with previous versions.

    Which snippet are you talking about by the way? Could you direct me to it? Was it in a PM to me?

    Thanks for the recommendations, its always good to get some critique on the scripts as testing every single possible outcome of the script in every single situation is impossible!

    @Mattirwin
    Thanks! Hopefully as mentioned in the above comment the mesh tool will get better but again, no garuntees.

    Jake
     
  29. xadhoom

    xadhoom

    Joined:
    Sep 2, 2010
    Posts:
    91
    Hi Jake,

    Yes, I refer to the snippet I´ve send you via pm. Here is a part of it:
    Code (csharp):
    1. // accumulate the distances between all ring vertices to calculate the overall length of the texture around the rope
    2. float accumRingDistance = 0;
    3. for(int index = 0; index < vertexRing.Length - 1; index++)
    4.    accumRingDistance += Vector3.Distance(vertexRing[index], vertexRing[index+1]);
    5.  
    6. // calculate the uv step per ring (along the rope)
    7. float uvRingStep = segmentLength / accumRingDistance;
    Its not shortest way but worked quiet well in my case.

    xad
     
  30. reveriejake

    reveriejake

    Joined:
    Jul 8, 2007
    Posts:
    815
    Thanks xad! I will put it in the next version.
     
  31. ivanzu

    ivanzu

    Joined:
    Nov 25, 2010
    Posts:
    2,065
    what does this thing do ,does it simulates a real rope lets say on rope sunspended bridge?
     
  32. reveriejake

    reveriejake

    Joined:
    Jul 8, 2007
    Posts:
    815
    It could if you wanted it to. It would take some time to build but I am pretty sure it would work ;). I have built a half rope bridge with it before (See Unity Creative Magazine for the older tutorial).

    Or you can check out the web player on my site http://reverieinteractive.com/games/simple-bridge

    Jake
     
  33. mattirwin

    mattirwin

    Joined:
    Jan 3, 2011
    Posts:
    13
    Hello Jake,

    I'm having trouble getting a smooth rope at the points where it attaches to PointA and PointB. No matter how I configure that joint, it won't behave like the rest of the rope. Is this because this joint is the connection point between physics-driven rigidbodies and the kinematic, fixed pointA and B?



    Please see the attached screen shot. I have setup a demo scene with two ropes that are children of an object being moved by a ping-pong script. PointA and PointB are fixed and the joints have 0 allowed twist and swing to prevent a piece-wise linear appearance of the rope. I paused the game while the ropes were moving to take the screen shot. The circled areas show the bending joints I'm trying to avoid. Interesting thing, one of ropes has a smooth joint at the PointB connection point, but I can't seem to repeat this even if I duplicated that rope.

    Here is an asset package containing the demo object as a prefab. Any help would be very appreciated, thanks.
    http://www.anatomicaltravel.com/research/wp-content/uploads/StringPair.unitypackage

    --Matt
     
  34. reveriejake

    reveriejake

    Joined:
    Jul 8, 2007
    Posts:
    815
    Hey Matt, I will take a look at this as soon as I get time! Let me know if you figure it out in the meantime!

    Thanks,
    Jake
     
  35. mattirwin

    mattirwin

    Joined:
    Jan 3, 2011
    Posts:
    13
    Thanks Jake,

    I will let you know if I can solve it in the meantime. Thanks for any time you can spend on it.

    Matt
     
  36. hiphish

    hiphish

    Joined:
    Nov 13, 2010
    Posts:
    598
    Hi

    Your rope Script looks pretty impressive, but I can't quite figure out how to do the following: I want to make a 2D platformer where the player can jump onto a rope/vine/whatever and grab onto it. While hanging on the rope he would be able to move up and down the rope (only along the rope of course) and jump off. Think of the original Donkey Kong Country and its swinging:

    Level 2, Ropey Rampage at 1:50, some ropes are just hanging down to be climbed, while others swing.

    So there are the following "issues":
    -The rope must only move in two dimensions.
    I have no idea if that would be possible with your rope, since it uses character joints. Maybe one could rewrite parts of the script to use cofigurable joints? I am afraid, even undstanding your script goes way beyond my abilities.

    -The character has somhow to stick to the rope
    My guess is, a simple script with an OnCollisionEnter() function, attached to each single joint, that parents the player to the joint would do the job. However, as far as I understand when I play the scene, the joints I was seeing in the hierarchy view are replaced by new ones. So how can I attach a script onto them?

    -How to move from joint to joint?
    So I jumped into a joint and I'm parented to it. Now I can move along my local Y-axis, which makes me move along the joint. But how do I parent the player to the next joint, once he reaches the end of it? I guess reaching the end of one joint would also make the player hit the collider of the neighbouring joint, automatically parenting him to that one, right?

    -Can I swing the rope myself?
    OK, this one is not that important, but it would be pretty cool, if the player could swing back and forth by pressing left and right. Maybe call rigidbody.AddForce() on the joint I'm attached to?

    -Ignore collision with everything else
    I already have a setup, where one layer cannot collide with anything but the player. How do I assign that layer to the rope's joints?

    -Make the rope snap into position
    if you look back at the swinging ropes in the Donkey Kong video above, you'll see that the rope is static until a monkey grabs onto it. Only then it begins swinging, and it probably snaps back once the monkey hops off. Could this be done through script? At least to make the rope stick until a player jumps into it. Again, jst a minor detail.


    I would really appreciate an answer, or at least a way how I could do it myself. I could do really cool stuff with it. Imagine a river of lava and a giant wave of lava trying to catch up to you. Your only chance of survival is swinging from vine to vine and hopping across huge boulders rolling through the lava (of course right into the wave) while monsters are trying to get you. It would be only half as fun vithout the ropes.
     
  37. reveriejake

    reveriejake

    Joined:
    Jul 8, 2007
    Posts:
    815
    @ HiPhish

    Hey thanks for the list of objectives! I have not yet made any add-ons to the current version of the rope script unfortunately but I do plan to in the future (Hopefully near future).

    For the meantime, if you find a good programmer, its very easy to make add-ons with the new version. Take a look at one of the included add-ons like the attach object add-on to see how it is done!

    I suggestion the following:

    OnCollide:
    - Find the position on the rope where your character is supposed to attach to.
    - Create a locator at that point and reference it in your script.
    - Use a little math to figure at where between 2 joints you are and how many divisions you want to take for the full length of the rope
    - Assign up/down keys to make your locator ride up and down the rope (I have actually done this before)
    - Finally parent your character to the climbing locator + offset.


    Hopefully this was somewhat helpful (Maybe more confusing)! I will keep everyone posted on any progress that is made with the scripts!

    Jake
     
  38. hiphish

    hiphish

    Joined:
    Nov 13, 2010
    Posts:
    598
    No problem, I considered it to be more useful than "how do U maek teh Character swing plz help asap lol thx bye!!!111!!" ;)

    The problem with finding a better programmer is that most people I know just don't care to learn anything outside their needed lectures. So I'm pretty much stuck on doing the programming on my own. Maybe I could convince people if I had more to show off. But for now there is no chance unfortunately.

    I tried to read through your Rope_AttachObjects script. Pretty confusing, since it's written in C# (I use JavaScript) and only one line off comment. *sigh* I guess, I'll just wait if you can cook up something cool. Thanks for your time anyway.


    Oh, one more thing, do add-ons have to be written in C# or could I use JavaScript?
     
  39. reveriejake

    reveriejake

    Joined:
    Jul 8, 2007
    Posts:
    815
    Yeah I will try to comment out everything for the next version ;) I have a REALLY bad habit of not commenting my code... Sorry!

    Jake
     
  40. hiphish

    hiphish

    Joined:
    Nov 13, 2010
    Posts:
    598
    OK, here is what I figured out so far: I can write a script, tht loops through all of the rope's joints and does something with them (in my case it adds a script to ech one of them).

    So here is my custom add-on:
    Code (csharp):
    1.  
    2.  
    3. using UnityEngine;
    4. using System;
    5. using System.Collections.Generic;
    6.  
    7. /*
    8. --- Add-On for Rope Script 3 ---
    9.  
    10. This script sets the layer of all segments to 12 (layer that can only collide
    11. which the player's collision emitter) and attaches a script to them.
    12. All instructions on what to do when collision occurs are to be made in that script, not here.
    13. */
    14.  
    15. [RequireComponent(typeof(Rope))]
    16. public class Rope_ParentOnCollision : MonoBehaviour
    17. {
    18.     //no idea what this does
    19.     [Serializable]
    20.     public class AttachedObject
    21.     {
    22.        
    23.     }
    24.    
    25.     public MonoBehaviour scriptToAttach;
    26.    
    27.     /* Script used variables */
    28.     Rope r = null;
    29.    
    30.    
    31.     void AwakeAddon()
    32.     {
    33.         //cache the rope's "Rope" component
    34.         r = gameObject.GetComponent<Rope>();
    35.        
    36.         //loop through all the rope's segments and do stuff
    37.         for (int i = 0; i < r.ropeSegments; i++)
    38.         {
    39.             //add the script
    40.             r.ropeJoints[i].AddComponent("ParentOnCollision");
    41.             //set the layer so it cannot collide with anything, including other ropes, except with the player (should be made adjustable)
    42.             r.ropeJoints[i].layer = 12;
    43.         }
    44.     }
    45. }
    46.  
    Basically I just copied the Rope_AttahObjects script and replaced some code.


    Next there is the ParentOnCollision script:
    Code (csharp):
    1.  
    2. function OnCollisionEnter (collision: Collision){
    3.     var playerObject = collision.gameObject.transform.parent.gameObject;
    4.    
    5.     Debug.Log (Time.time + collision.gameObject.name + gameObject.name + playerObject.name);
    6.     playerObject.transform.parent = transform;
    7.     playerObject.GetComponent(MyController).enabled = false;
    8.     playerObject.GetComponent(ClimbingController).enabled = true;
    9. }
    10.  
    11. function OnCollisionExit (collision: Collision){
    12.     var playerObject = collision.gameObject.transform.parent.gameObject;
    13.    
    14.     Debug.Log (Time.time + playerObject.name + gameObject.name + "exited collision");
    15.     playerObject.transform.parent = null;
    16.     playerObject.GetComponent(MyController).enabled = true;
    17.     playerObject.GetComponent(ClimbingController).enabled = false;
    18. }
    19.  
    As I mentioned before, the player is carrying around a collider object that has no other purpose, than to collide with enemies and the rope in this case. It cannot collide with anything else. So I use that "sensor" to detect collision instead of the player's CharacterController component.


    So here is where I hit a wall. Your rope is all fine and stuff when it comes to 3D, but in a 2D game it has to be more restricted. There should be no rotation around the X- and Y-Axis and it must not move along the Z-Axis. I tried adding a ConfigurableJoint compionents through script, but that only resulted in a mess. My guess is that the joints would have to be restriced from the very first beginning.

    Restricting rotation is important, because otherwise the player will receive the segment's rotation information and spinn all over the place. Restricting Z-Motion is important for two reasons. First of all, if the rope is behind or in front of the player you cannot see it, and it just looks like the player is passing right through the rope. The other reason is that the player could be moved along the Z-Axis by the joint, thus missing platforms and other objects, which are all aligned at Z=0
     
    Last edited: Jan 19, 2011
  41. reveriejake

    reveriejake

    Joined:
    Jul 8, 2007
    Posts:
    815
    OnUpdate
    Foreach GameObject go in ropeJoints
    go.transform.position = new Vector3( 0 , go.transform.y , go.transform.position.z ); <---- That will restrict the rope to the X axis


    Try something like the above using the addon script.
     
  42. hiphish

    hiphish

    Joined:
    Nov 13, 2010
    Posts:
    598
    OK, tried it, ran into something else: from my understanding the Y-Axis stands for height. But it seems as if for your rope it is the Z-Axis. I made a screenshot:

    Sure, I can simply restrict rotation along the "wrong" axes, but how am I supposed to properly parent the player?

    So two things:
    -the joints have to start out rotated the traditional way (X = horizontal, Y = vertical, Z = depth)
    -the joints' colliders have to face along the Y-Axis

    So it should look something like this:

    (not sure why you have the centre offset by -1 in Z)

    Obviously you are the expert, not me, so you probably know best how to get these things done. i just hope I can help make rope script even better. Thanks for your support.
     
  43. dtntr

    dtntr

    Joined:
    Oct 6, 2009
    Posts:
    26
    Thanks! Very useful script.
     
  44. reveriejake

    reveriejake

    Joined:
    Jul 8, 2007
    Posts:
    815
    @dtntr

    Your welcome, glad you like it!

    @HiPhish

    The last rope script I made I was able to successfully constrain the joints to one axis so I know that this is possible. And the reason the Z-axis is the direction is because the rope is built in the Z-axis and rotated into position. That is the secret to how the rope script works. Since you cannot assign a rotation value to Cylinder colliders (The option is 0,1,or2) then the solution was to build the whole rope on a common axis and rotate the joints using "LookAt". It seemed to work very well.

    The solution to the climbing script might be something other than the direction your heading? Do not get to attached to one single solution and experiment with many different ideas! Otherwise you will drive yourself crazy trying to find a work around! ;) I know the solution isn't very easy otherwise someone would have done it by now. I have personally made several attempts and only got close once!

    Hopefully I didn't sound too coarse my comment has good intentions!

    Jake
     
  45. hiphish

    hiphish

    Joined:
    Nov 13, 2010
    Posts:
    598
    OK, thanks for you patience, but this is getting way too big for my abilities.

    So I basically said screw it and made my own rope, segment by segment. It's by far not as elegant as your Rope Script and is a ton of work for every single rope, but at least I get things done. So here is how I did it:

    The rope consits of capsules, each of them with a charcter joint (except the topmost one). Each joint has the capsule above it connected to. i still have to experiment with the swing axis setting to find out what exactly it does. The topmost segment has a hinge joint, connected to the world and an axis of (0, 0, 1).

    All segments have a script that restricts them to 2D
    Code (csharp):
    1.  
    2. //prevents the object from moving and rotating in a way unfit for 2D
    3.  
    4. function FixedUpdate () {
    5.     transform.localPosition.z = 0;
    6.     transform.eulerAngles.x = 0;
    7.     transform.eulerAngles.y = 0;
    8. }
    9.  
    it might not be perfect performance-wise, but using cofigurable joints and restriction instead of CharacterJoints lead to some weird stuff.

    Then I made all segments' colliders into triggers and attached this script to them:
    Code (csharp):
    1.  
    2. function OnTriggerEnter (collision: Collider){
    3.     var playerObject = collision.gameObject.transform.parent.gameObject;
    4.     playerObject.GetComponent(ClimbingController).AddSegment();
    5.    
    6. //  Debug.Log (Time.time + collision.gameObject.name + gameObject.name + playerObject.name);
    7.     playerObject.transform.parent = transform;
    8.     playerObject.GetComponent(ClimbingController).SetXOffest(0.0);
    9.     playerObject.GetComponent(MyController).enabled = false;
    10.     playerObject.GetComponent(ClimbingController).enabled = true;
    11. }
    12.  
    13. function OnTriggerExit (collision: Collider){
    14.     var playerObject = collision.gameObject.transform.parent.gameObject;
    15.     playerObject.GetComponent(ClimbingController).RemoveSegment();
    16.    
    17. //  Debug.Log (Time.time + playerObject.name + gameObject.name + "exited collision");
    18.     //the player will be touching several sements at a time. We want to dismout the player
    19.     //only if he exited the last trigger he was in
    20.     if(playerObject.GetComponent(ClimbingController).GetSegments() == 0){
    21.         playerObject.transform.parent = null;
    22.         playerObject.GetComponent(MyController).enabled = true;
    23.         playerObject.GetComponent(ClimbingController).enabled = false;
    24.     }
    25. }
    26.  
    AddSegment(), RemoveSegment and GetSegments() are to keep track of how many segments the player is touching. Only if he is not touching any should he be released, not if he left one, but still touches another one.
     
  46. reveriejake

    reveriejake

    Joined:
    Jul 8, 2007
    Posts:
    815
    @HiPhish

    Hey sorry for the frustration and I am glad to see that you found a solution even though it is way more difficult (The whole reason I made the rope script in the first place).

    Let me know how your climbing script works once you get it working!

    @Everyone

    Sorry guys for not providing much support lately. Thats one of the reasons why I chose to provide this script for a donation and not to "Sell" this script. I get opportunities to work on various other projects and I like to have the ability to move from one to the other without feeling attached to any single project.

    Thanks ,
    Jake
     
  47. hiphish

    hiphish

    Joined:
    Nov 13, 2010
    Posts:
    598
    What a coincidence, I just finished my rope stuff. Now I can jump onto it, climb it, swing it, slip down and jump off, Tarzan like. The only thing that can happen now is the player swinging too much back and forth, but that's his fault then.

    The climbing controls script is really no big deal, I had a roughly working version assembled in less than half an hour, and I refined it today:
    Code (csharp):
    1.  
    2. //make speed for climbing and slipping idepentent, just in case
    3. var climbingSpeed = 3.0;
    4. var slippingSpeed = 3.0;
    5. var horizontalSpeed = 3.0;
    6.  
    7. //a nice little touch, disable for more control
    8. var slipsDownABit = true;
    9. var slipsUpABit = false;
    10.  
    11. //enable to be abl to move horizontally
    12. var canMoveHorizontally = false;
    13. //enabl to apply force on the carrier (overrides the above)
    14. var canShakeCarrier = false;
    15.  
    16. //these will be used for switching between climbing and sliding
    17. @System.NonSerialized
    18.     var climbingSwitch = 0;
    19. @System.NonSerialized
    20.     var slippingSwitch = 0;
    21.    
    22. //this will keep track of how many segments we are climbing at the moment
    23. private var amountOfSegments = 0;
    24.  
    25. //the horizontal offset for climbing the target (0 is reccomended), will be set by object to climb
    26. private var xOffset = 0.0;
    27.  
    28. function Update () {
    29.     //first snap to the thing we climb
    30.     transform.localPosition.x = xOffset;
    31.    
    32.     //cache raw and smoothed axis values
    33.     var rawVerticalAxis = Input.GetAxisRaw("Vertical");
    34.     var smoothVerticalAxis = Input.GetAxis("Vertical");
    35.     var rawHorizontalAxis = Input.GetAxisRaw("Horizontal");
    36.     var smoothHorizontalAxis = Input.GetAxis("Horizontal");
    37.    
    38.     //set the switches
    39.     if (smoothVerticalAxis > 0){
    40.         //climbing up
    41.         climbingSwitch = 1;
    42.         slippingSwitch = 0;
    43.     } else if (smoothVerticalAxis < 0){
    44.         //sliding down
    45.         climbingSwitch = 0;
    46.         slippingSwitch = 1;
    47.     } else{
    48.         //hanging still
    49.         climbingSwitch = 0;
    50.         slippingSwitch = 0;
    51.     }
    52.    
    53.     //now move, but only if a button is pressed OR shortly after releasing down (or up) to simulate some minor sliding
    54.     if (rawVerticalAxis != 0 || (smoothVerticalAxis < 0  slipsDownABit) || (smoothVerticalAxis > 0  slipsUpABit))
    55.         transform.Translate(Vector3.up * Mathf.Pow(climbingSpeed *smoothVerticalAxis, climbingSwitch) *  Mathf.Pow(slippingSpeed * smoothVerticalAxis, slippingSwitch) * Time.deltaTime);
    56.     //horizontal movement
    57.     if(smoothHorizontalAxis != 0  canMoveHorizontally)
    58.         transform.Translate(Vector3.right * horizontalSpeed * smoothHorizontalAxis * Time.deltaTime);
    59.        
    60.     //shake it!
    61.     if(canShakeCarrier)
    62.         transform.parent.gameObject.rigidbody.AddRelativeForce(Vector3.right * smoothHorizontalAxis * 10);
    63.        
    64.     if(Input.GetButtonDown("Jump"))
    65.         transform.parent.gameObject.GetComponent(ParentOnCollision).JumpOff(rawHorizontalAxis, gameObject);
    66.    
    67. //  Debug.Log (amountOfSegments);
    68. }
    69.  
    70. function LateUpdate(){
    71.     //set the rotation to fit the parent, if parented
    72.     if(transform.parent)
    73.         transform.rotation = transform.parent.transform.rotation;
    74. }
    75.  
    76. function AddSegment(amount: int){
    77.     amountOfSegments += amount;
    78. }
    79.  
    80. function SetSegments(someValue: int){
    81.     amountOfSegments = someValue;
    82. }
    83.  
    84. function GetSegments(){
    85.     return amountOfSegments;
    86. }
    87.  
    88. function SetXOffest(offset: float){
    89.     xOffset = offset;
    90. }
    91.  
    92. function SetUpController(newClimbingSpeed: float, newSlippingSpeed: float, newHorizontalSpeed: float, slipUp: boolean, slipDown: boolean, moveHorizontally: boolean, shake: boolean){
    93.     climbingSpeed = newClimbingSpeed;
    94.     slippingSpeed = newSlippingSpeed;
    95.     horizontalSpeed = newHorizontalSpeed;
    96.     slipsDownABit = slipUp;
    97.     slipsUpABit = slipDown;
    98.     canMoveHorizontally = moveHorizontally;
    99.     canShakeCarrier = shake;
    100.    
    101.     //override canMoveHorizontally if needed
    102.     if(canShakeCarrier)
    103.         canMoveHorizontally = false;
    104. }
    105.  
    I haven't tried the horizontal movement yet, nor the SetUpController function, but I wrote them just in case I want to use them for something else, like climbing a wall in the background. Kind of like these things, or whatever.
     
  48. reveriejake

    reveriejake

    Joined:
    Jul 8, 2007
    Posts:
    815
    Hey! Glad to hear you got a solution built up. And this is on your own rope setup and not the rope script correct?

    Jake
     
  49. hiphish

    hiphish

    Joined:
    Nov 13, 2010
    Posts:
    598
    Exactly. I looked at what components the segments have, when the level is playing and figured, I could assemble something similar but make it the way I want from the beginning. Here is a little show-off video. Can you recognize the level? :D


    The graphics are actually smooth, the whole thing jitters while I am recording.
     
    Last edited: Jan 22, 2011
  50. da7thSkull

    da7thSkull

    Joined:
    Feb 15, 2010
    Posts:
    22
    hi

    this sound's and look very nice, and if u share this with the community a dream come true for me. because me as a 3d artist, never able to do stuff like this.

    keep on rocking

    cheers

    michael
     
unityunity