Obi Official Forum

Full Version: Question About Making Grappling Hook
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi, my intention is making grappling hook effect. But not like in the examples. My rope is already initialized on scene. What I want to do when I press the mouse button it scales up to object's position, then pinned to the object and stay on this length.

I tried it like this;

Code:
private IEnumerator Attach_Coroutine()
   {
       _rope.RemoveFromSolver(null);

       Quaternion lookRot =
           Quaternion.LookRotation(_rope.transform.position - GameManager.Instance.Ball.transform.position, -Vector3.forward);
       lookRot.x = 0.0f;
       lookRot.y = 0.0f;
       _rope.transform.rotation = lookRot;

       float distanceToBallFromHandle = Vector3.Distance(GameManager.Instance.Ball.transform.position, this.transform.position);
       float distanceToBallFromRopeEnd = distanceToBallFromHandle - _rope.CalculateLength();

       float attachSpeed = GameManager.Instance.handleAttachSpeed;

       _rope.AddToSolver(null);
       while (_rope.CalculateLength() <= distanceToBallFromHandle)
       {
           _ropeCursor.ChangeLength(_rope.RestLength + attachSpeed * Time.deltaTime);
           yield return null;
       }

       _ropePinConstraints.RemoveFromSolver(null);
       ObiPinConstraintBatch pinConstraintsBatch = _rope.PinConstraints.GetFirstBatch();
       pinConstraintsBatch.AddConstraint(_rope.UsedParticles-1, GameManager.Instance.Ball.GetComponent<ObiColliderBase>(), Vector3.zero,
           Quaternion.identity, 0);
       
       _ropePinConstraints.AddToSolver(null);
       
       _isAttached = true;
   }

But the attachment point is not the last particle of the rope.

I attached a photo that demonstrate what I want.

Thanks in advance.
You can't "rotate" a rope whilst being simulated, it makes no sense at all. Deformable objects in general (not just ropes) cannot be transformed using a single matrix, as rotations are rigid transforms by definition: https://en.wikipedia.org/wiki/Rigid_transformation

Even if you could rotate the entire rope, gravity would immediately make it point downwards again after rotating it... this approach is just not a good idea.

I'd use external forces to coerce the rope particles (or at least the last particle) into moving towards the player. The solver has a externalForces array that you can write per-particle forces into, same as you would set velocities or positions.