// Start is called before the first frame update void Start() { Material ropeMaterial = new Material(Shader.Find("Unlit/Color")); GameObject gun = GameObject.CreatePrimitive(PrimitiveType.Cylinder); Rigidbody gunRb = gun.AddComponent <Rigidbody>(); gunRb.isKinematic = true; Destroy(gun.GetComponent <Collider>()); gun.transform.position = transform.position + 0.25f * transform.forward + 0.25f * transform.right; gun.transform.rotation = transform.rotation; gun.transform.parent = transform; VerletRope verletRope = gun.AddComponent <VerletRope>(); //VerletRope verletRope = gameObject.AddComponent<VerletRope>(); verletRope.BuildRope(physicsAnchor, 6, maxRopeLength, ropeMaterial); verletRope.Spring = 5000.0f; verletRope.Damper = 1000.0f; }
IEnumerator LaunchHookCoroutine() { ropeRenderer.enabled = true; ropeRenderer.positionCount = 2; while (Vector3.Distance(transform.position, hook.transform.position) < maxRopeLength) { Collider[] colliders = new Collider[1]; LayerMask hookableLayerMask = LayerMask.GetMask("HookableLayer"); LayerMask ballLayerMask = LayerMask.GetMask("Ball"); if (Physics.OverlapSphereNonAlloc(hook.transform.position, 0.1f, colliders, hookableLayerMask | ballLayerMask) > 0) { //ropeRenderer.enabled = false; if (colliders[0].tag == "Hookable" || colliders[0].tag == "BounceBall") { hook.GetComponent <Rigidbody>().isKinematic = true; hook.transform.parent = colliders[0].transform; isGrappled = true; verletRope = gameObject.AddComponent <VerletRope>(); verletRope.BuildRope(hook.transform, 6, maxRopeLength, ropeMaterial); verletRope.Spring = 5000.0f; verletRope.Damper = 1000.0f; state = HookState.Attached; } else { state = HookState.Retracting; StartCoroutine(RetractHookCoroutine()); } yield break; } ropeRenderer.positionCount = 2; ropeRenderer.SetPositions(new Vector3[] { transform.position, hook.transform.position }); yield return(null); } state = HookState.Retracting; //ropeRenderer.enabled = false; StartCoroutine(RetractHookCoroutine()); yield return(null); }