Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to teleport a rope
#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


Messages In This Thread
How to teleport a rope - by HPx___ - 23-01-2024, 06:37 PM
RE: How to teleport a rope - by josemendez - 24-01-2024, 07:56 AM
RE: How to teleport a rope - by HPx___ - 24-01-2024, 09:11 AM
RE: How to teleport a rope - by josemendez - 24-01-2024, 09:53 AM
RE: How to teleport a rope - by HPx___ - 24-01-2024, 11:27 AM
RE: How to teleport a rope - by josemendez - 24-01-2024, 12:01 PM