Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help  Question About Making Grappling Hook
#1
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.


Attached Files Thumbnail(s)
   
Reply


Messages In This Thread
Question About Making Grappling Hook - by relevantname - 14-04-2020, 02:31 PM