Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
3
Question by Ollenator · Jan 08, 2015 at 01:19 PM · hingejointropepull

Pulling up a Rope

Hi Guys!

I made a physical rope, using empty gameobjects, hingeJoints and line renderer - and it is working remarkably well. However, I would like to be able to pull in the rope (like rolling up around your arm, and pulling up objects) and that.. I cannot do :(

I uses this code to generate the rope between two characters: using UnityEngine; using System.Collections; using System.Collections.Generic;

 public class RopeGeneratorScript : MonoBehaviour {
 
     private LineRenderer line;
     private List<GameObject> joints;
     private int vertexCount;
     private float NTDistance;
     public GameObject emptyPrefab;
     public GameObject neil;
     public GameObject thomas;
 
     // Use this for initialization
     void Start () {
         vertexCount = (((int)Vector3.Distance (neil.transform.position, thomas.transform.position))*4)-1;
         joints = new List<GameObject> ();
         line = GetComponent<LineRenderer> ();
         line.SetWidth (0.05f, 0.05f);
         line.SetColors (Color.black, Color.blue);
         for (int i = 0; i < vertexCount; i++) {
             joints.Add((GameObject)Instantiate(emptyPrefab, new Vector3(transform.position.x, transform.position.y, transform.position.z + (i+1)*0.25f), Quaternion.identity));
         }
         for(int j = 0; j < joints.Count-1; j++){
             joints[j].transform.parent = this.transform;
             joints[j].GetComponent<HingeJoint>().connectedBody = joints[j+1].rigidbody;
         }
         joints [0].AddComponent<HingeJoint>().connectedBody = thomas.rigidbody;
         joints [vertexCount - 1].GetComponent<HingeJoint> ().connectedBody = neil.rigidbody;
     }
     
     // Update is called once per frame
     void Update () {
         line.SetVertexCount (joints.Count);
         for(int i = 0; i < joints.Count; i++){
             line.SetPosition(i, joints[i].transform.position);
         }
     }
 }

As I said it works quite well - here is a screen of how it looks like: alt text

alt text

Now picture one shows how it looks when its started - BUT in picture #2 I would like to be able to pull the lower character up, using the rope.. I tried extending and shorting the length of the rope, but it just didn't work very well at all - here is my attempt:

 void UpdateRobe(){
         int oldVertexCount = vertexCount;
         vertexCount = (((int)Vector3.Distance (neil.transform.position, thomas.transform.position))*4)-1;
 
         if (vertexCount == oldVertexCount) {
             return;
         } else if (vertexCount > oldVertexCount) {
             joints [oldVertexCount - 1].GetComponent<HingeJoint> ().connectedBody = null;
             int vertexDifference = vertexCount - oldVertexCount;
             for (int i = 0; i < vertexDifference; i++) {
                 joints.Add ((GameObject)Instantiate (emptyPrefab, new Vector3 (joints [oldVertexCount - 1].transform.position.x, joints [oldVertexCount - 1].transform.position.y, joints [oldVertexCount - 1].transform.position.z + (i + 1) * 0.25f), Quaternion.identity));
             }
             for (int j = oldVertexCount-1; j < vertexCount-1; j++) {
                 joints [j].transform.parent = this.transform;
                 joints [j].GetComponent<HingeJoint> ().connectedBody = joints [j + 1].rigidbody;
             }
                 joints [vertexCount - 1].GetComponent<HingeJoint> ().connectedBody = neil.rigidbody;
         } else if (vertexCount < oldVertexCount) {
             //int vertexDifference = oldVertexCount - vertexCount;
             joints[oldVertexCount-1].GetComponent<HingeJoint>().connectedBody = null;
             for(int k = oldVertexCount-1; k > vertexCount; k--){
                 Destroy(joints[k]);
                 joints.RemoveAt(k);
             }
             joints[vertexCount-1].GetComponent<HingeJoint>().connectedBody = neil.rigidbody;
         }
 
 
     }

So I was thinking if instead of making the rope longer and shorter than I could just wind it up and out, but I have no idea where to start really :O this is my first attempt with ropes so I on shaky ground as it is :)

Best Regards Olle

screenshot01.jpg (69.6 kB)
screenshot02.jpg (42.1 kB)
Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by RetepTrun · Jan 09, 2015 at 03:01 AM

Nice. The rope looks fun as is.

My $0.2:

  • Tried shortening the rope by scaling down all its links instead of deleting them?

  • Adding force to the guy being hauled up as you delete the links?

  • A different but less nice looking approach to ropes? http://gamedevelopment.tutsplus.com/tutorials/swinging-physics-for-player-movement-as-seen-in-spider-man-2-and-energy-hook--gamedev-8782

Comment
Add comment · Show 6 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Ollenator · Jan 09, 2015 at 10:14 AM 0
Share

Thanks for the reply

  • Not sure what you mean? unless you are thinking of the individual lings as cylinders or cubes. Each link consist simply of an empty gameObject and a sphere collider. So each hingeJoint is connected to a mathematical point in space - and as far as I can tell there is no way to scale the length of the joint after you run the game? Have tried to move around the anchors at runtime, but it doens't seem to make much difference :(

  • Have not tried that, may be a good idea to try it ;) However that still leaves me with the problem of extending the rope length again, which worked really poorly for me as well :(

avatar image RetepTrun Ollenator · Jan 09, 2015 at 08:00 PM 0
Share

good luck then. $$anonymous$$y last idea is just provide the characters with a cylinder and a crank and turn it around like this thing for buy I saw awhile ago. alt text

avatar image vexe · Jan 09, 2015 at 08:13 PM 0
Share

@Ollenator please post comments as comments, not answers

avatar image Ollenator · Jan 12, 2015 at 07:59 AM 0
Share

@vexe sorry I'll remember that in the future :)

@RetepTrun I had the same thought, and I might have to try it out - though first I'm trying to add negative force to individual joints, but I will definiately try out the cylinder/crank option as well.

avatar image Ollenator · Jan 12, 2015 at 08:49 AM 1
Share

I just tried making a crank, and it works fantastic! It needs A LOT of polishing - but the initial draft works wonders.

For other devs. who are attempting this I simply made a cylinder, and attached to additional cylinders on either side (slimmer and wider) - Each cylinder has a capsule collider, and the large middel cylinder has a rigidbody. The end of the rope is attached to the cylinder, and then I simply rotate the object around its own Y-axes. You need enough angle per second to add enough force to pull the rope and the object in the end (for me about 500) but it depends on the weight of the object. Here is a screenshot:

alt text

hope it helps some people out there!

screenshot03.jpg (27.9 kB)
avatar image sergioabril · Sep 20, 2016 at 12:42 PM 0
Share

@Ollenator Hi! I'm trying to achieve something similar and I decided to use your script as a start point (looked really nice and easy). However, when I try to do it, as soon as press play, my rope goes crazy from the beginning.

How must be the hingeJoint configured in the Prefab? I'm starting to learn how to tune joints, but I don't think I fully understand them yet...

Here a GIF:

https://dl.dropboxusercontent.com/u/1209521/sept-20-2016%2014-40-13.gif

avatar image
0

Answer by Ollenator · Sep 21, 2016 at 11:19 AM

That do look rather crazy :) But to be honest, I don't remember the settings directly. It has been a long time since I used the project.

I do recall something about my rope doing the same thing as yours, but to be honest, I can't remember what I did to fix it :(

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

2D rope (hinge and distance) on only ONE axis 0 Answers

get a rigidbody rope move with my character 1 Answer

Translating a gameObject with a Hinge joint? 0 Answers

2D hinge joint with sprite 0 Answers

jungle swing type game ...? 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges