Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Physic Make a Rope

Discussion in 'Scripting' started by esitoinatteso, Oct 15, 2014.

  1. esitoinatteso

    esitoinatteso

    Joined:
    Sep 23, 2013
    Posts:
    26
    Hi there! I reckon my question might seem weird but a Rope GameObject is precisely what I'd like to make.

    You know how a rope behaves in the real world? Its shape loosely varies depending on the surface on which its lying, especially when its unrolled.
    Every " segment" " moves" along with the others as if it was a single entity.
    It can bend, make knots, brake and so on.

    So, everybody knows what a rope is and how it acts, question is, how would you make one with physic, in Unity?

    What I've tried so far is to create a Cube, attach it a script to spawn other Cubes and then attach a script to these Cubes to move them properly.
    Every Cube follows the first one and they stick together thanks to AddForce, that starts applying a force every time they move out of a specific range.
    Obviously it's not working, I guess I've missed something.

    So, maybe this idea to create a head of the queue and then telling everybody to follow it while keeping in line is not so smart. How would you do that?
    I mean, if you're kind enough to post some code it's ok I guess, but I'm just fine if you care to reply giving me your two cents!
    Thanks for your time!

    P.S.: I can show you my messy code if you need it!
     
  2. esitoinatteso

    esitoinatteso

    Joined:
    Sep 23, 2013
    Posts:
    26
    Hi again!
    I've found out my logic was correct but my method was not!
    I've studied Hinge and Fixed Joints and now I've built a rope, yay!

    BUT I've a problem... if I instantiate the rope from code and give every segment a position using its transform so they don't overlap everything is fine.
    If I try to instantiate those segments in the same position and tell them not to collide ( disabling collisions of their hinge joints) stuff won't work! ( they get stuck together)

    What could it be?
    Again, if code is needed I can provide it ( it's still messy, I'll rewrite it once I'm through all issues)!