14-04-2020, 02:31 PM
(This post was last modified: 14-04-2020, 02:32 PM by relevantname.)
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;
But the attachment point is not the last particle of the rope.
I attached a photo that demonstrate what I want.
Thanks in advance.
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.