Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to teleport a rope
#1
Hi,

I would like to teleport a rope in Unity.

Teleport method move only one end of the rope.

How to move the whole rope in one time, without streching it ?

Thanks,
Reply
#2
(23-01-2024, 06:37 PM)HPx___ Wrote: Hi,

I would like to teleport a rope in Unity.

Teleport method move only one end of the rope.

How to move the whole rope in one time, without streching it ?

Thanks,

Hi,

rope.Teleport() teleports the entire rope, as it iterates trough all particles in it. Note that it there's active attachments on the rope, teleporting won't "undo" the attachments so the rope will stretch unless you remove the attachments first.

could you explain your use case in a bit more detail?

kind regards,
Reply
#3
Hi,




I have a rope which is dangling.


I want to hang it somewhere else.





When I use Teleport, only the top position move. The rope is swinging before stabilizing.




I have a Rigidbody at the second end of the rope, do I have to move it manualy ?


   




Thanks,


Harold
Reply
#4
(24-01-2024, 09:11 AM)HPx___ Wrote: I have a Rigidbody at the second end of the rope, do I have to move it manualy ?

Yes of course, teleporting the rope will affect the rope only. The rigidbody won't move on its own unless you tell it to.

What's probably happening now is that you're teleporting the rope and the rigidbody is left behind, so it then swings from its previous position to accommodate to the new position of the rope.

let me know if you need help with this,

kind regards
Reply
#5
It's better but I still have inertia in the rope.

Before move
   

After move
   


My rope is created by this code :
Code:
// Rope
        rope = (GameObject)Instantiate(Resources.Load("Obi/Prefabs/ObiRope"));
        rope.name = "Rope 0";
        rope.transform.parent = transform;
        rope.transform.localPosition = Vector3.zero;
        rope.transform.localRotation = Quaternion.identity;

        // Create the blueprint:
        var blueprint = ScriptableObject.CreateInstance<ObiRopeBlueprint>();

        // Build the rope path:
        blueprint.path.AddControlPoint(Vector3.zero, -Vector3.forward, Vector3.forward, Vector3.up, 0.1f, 0.1f, 1, 1, Color.white, "upper");
        blueprint.path.AddControlPoint(Vector3.forward, -Vector3.forward, Vector3.forward, Vector3.up, 0.1f, 0.1f, 1, 1, Color.white, "lower");
        blueprint.path.FlushEvents();

        // Generate particles/constraints:
        blueprint.GenerateImmediate();

        var obiRope = rope.GetComponent<ObiRope>();
        obiRope.ropeBlueprint = blueprint;

        var attach = rope.GetComponent<ObiParticleAttachment>();
        attach.particleGroup = rope.GetComponent<ObiRope>().ropeBlueprint.groups[0];
        attach.attachmentType = ObiParticleAttachment.AttachmentType.Static;
        attach.target = rope.transform;

        obiRope.enabled = true;

       ropeEnd = new GameObject("RopeEnd 0");
        ropeEnd.transform.parent = transform.parent;
        ropeEnd.transform.position = new Vector3(2,4,0);
        ropeEnd.transform.rotation = Quaternion.identity;
        var caps = ropeEnd.AddComponent<SphereCollider>();
        caps.radius = 0.05f;
        var rigid = ropeEnd.AddComponent<Rigidbody>();
        rigid.isKinematic = false;
        rigid.mass = 5;
        rigid.angularDrag = 5;
        rigid.drag = 0.5f;

        var attach2 = rope.AddComponent<ObiParticleAttachment>();
        attach2.particleGroup = rope.GetComponent<ObiRope>().ropeBlueprint.groups[1];
        attach2.attachmentType = ObiParticleAttachment.AttachmentType.Dynamic;
        attach2.target = ropeEnd.AddComponent<ObiCollider>().transform;

Code:
    void Teleport()
    {
        //ropeEnd.GetComponent<Rigidbody>().isKinematic = true;
        var r = rope.GetComponent<ObiRope>();
        r.Teleport(transform.position + new Vector3(3, 0, 0), Quaternion.identity);

        ropeEnd.transform.position = ropeEnd.transform.position + new Vector3(3, 0, 0);
        ropeEnd.GetComponent<Rigidbody>().MovePosition(ropeEnd.transform.position);
    }
Reply
#6
I'm not sure I entirely understand your code, I think I'm missing some context. You're adding two control points, one at the rope's local zero, and another one at 0,0,1. The tangent for both points is 0,0,-1, which in this case will result in a kink at the start of the rope, should be 0,0,1 (that is, positive Vector3.forward) for the first point:

Code:
blueprint.path.AddControlPoint(Vector3.zero, -Vector3.forward, Vector3.forward, Vector3.up, 0.1f, 0.1f, 1, 1, Color.white, "upper");
blueprint.path.AddControlPoint(Vector3.forward, -Vector3.forward, Vector3.forward, Vector3.up, 0.1f, 0.1f, 1, 1, Color.white, "lower");

However your rigidbody is at 2,4,0, so unless your rope transform is *exactly* at 2,4,-1, the rigidbody won't be even close to the end of the rope.

Also note that the following code doesn't make any sense: you're moving the rigidbody transform to a position, then moving it again to the exact same position. Either use transform.position or rigidbody.MovePosition, not both.

Code:
ropeEnd.transform.position = ropeEnd.transform.position + new Vector3(3, 0, 0);
ropeEnd.GetComponent<Rigidbody>().MovePosition(ropeEnd.transform.position); // redundant

Making sure the rope is at 2,4,-1 and removing the call to MovePosition, I've tried your code and it works fine for me (in the video, I'm calling Teleport() upon pressing T in the keyboard):



cheers,
Reply