protected void OnCollisionEnter2D(Collision2D p_collision) { if (grappleState != E_GrappleState.Travelling) { return; } Debug.Log("Triggered the claw"); if (p_collision.collider.tag != ClawTarget.TAG) { Debug.Log("Not valid target"); Debug.Log(p_collision.collider.tag); return; } grappleState = E_GrappleState.Connecting; currentTarget = p_collision.collider.GetComponent <ClawTarget>(); SetCollisionEnabled(false); _animationTweens.Add(DOTween.To((float value) => { SetClosedVisual(value); }, 0f, 1f, AttachAnimationLength).SetEase(Ease.InExpo)); fixedJoint.connectedBody = currentTarget.GetComponent <Rigidbody2D>(); fixedJoint.enabled = true; var currentPos = rect_transform.position; var targetPos = p_collision.GetContact(0).point - _fireDirection * 0.2f; //DebugExtension.DebugArrow(collision.GetContact(0).point, collision.GetContact(0).normal * 10f, Color.red, 10f, true); this._currentRotation = rect_transform.rotation; var hitNormal = p_collision.GetContact(0).normal; var normalRotation = Quaternion.Euler(0, 0, Mathf.Atan2(hitNormal.y, hitNormal.x) * 180f / Mathf.PI - 90f); this._targetRotation = Quaternion.Lerp(_currentRotation, normalRotation, 0.5f); _animationTweens.Add(DOTween.To((float value) => { SetClosedVisual(value); }, 0f, 1f, AttachAnimationLength).SetEase(Ease.InExpo)); var tween = DOTween.To(() => { return(currentPos); }, (Vector3 vec) => { rect_transform.position = vec; }, targetPos, AttachAnimationLength).SetEase(Ease.InExpo); tween.onUpdate += () => { tween.target = p_collision.GetContact(0).point - _fireDirection * 0.2f; }; tween.onComplete += () => { Debug.Log("Attached the claw"); _trailRenderer.emitting = false; currentTarget.ClawConnect(); grappleState = E_GrappleState.Retracting; }; _animationTweens.Add(tween); }
protected void Awake() { sfx_PortalShot = GetComponent <StudioEventEmitter>(); _portalTarget = GetComponentInChildren <PortalTarget>(); var pos = _portalTarget.transform.position; pos.z = 0f; _portalTarget.transform.position = pos; _clawTarget = GetComponent <ClawTarget>(); if (_clawTarget == null) { Debug.LogError("Not a valid portal"); return; } _clawTarget.OnShipUnDocked += OnShipLeave; }