Ejemplo n.º 1
0
    public IEnumerator JoinTheFlow()
    {
        if (CheckClosestWaypoint() != null)
        {
            impactCloud.Play();
            playerController.anim.SetBool("isSwimming", true);

            Transform detectedWaypoint = CheckClosestWaypoint();
            PlayerController.controlsAble = false;
            //Get the detected flow & position on the path
            FlowInstance targetFlow       = detectedWaypoint.GetComponentInParent <FlowInstance> ();
            float        targetPercentage = CheckPathPercentage(targetFlow);

            //Init for lerp
            Vector3 originPosition = transform.position;

            //Keep up vector for flow movement
            //New UP
            Vector3 upDirection = transform.up;

            //Resets local rotation of the mesh inside the player
            StartCoroutine(playerController.ResetMeshRotation());

            float vol = soundMan.flowSource.volume;
            //Lerp towards target point on the path
            for (float i = 0; i < 1; i += Time.deltaTime * inSpeed)
            {
                transform.position = Vector3.Lerp(originPosition, iTween.PointOnPath(targetFlow.waypoints, targetPercentage), joiningCurve.Evaluate(i));
                transform.rotation = Quaternion.LookRotation(transform.forward, upDirection);

                //Lerp in the flow sound

                if (!soundMan.flowSource.isPlaying)
                {
                    soundMan.flowSource.Play();
                }

                soundMan.flowSource.volume = Mathf.Lerp(0f, vol, i);

                yield return(new WaitForFixedUpdate());
            }

            transform.position = iTween.PointOnPath(targetFlow.waypoints, targetPercentage);

            leftSwimBubbles.Play();
            rightSwimBubbles.Play();

            //Create flow parent
            GameObject flowParent = new GameObject("FlowParent");
            flowParent.transform.position = transform.position;
            flowParent.transform.rotation = transform.rotation;
            flowMovement     = flowParent.AddComponent <FlowMovement> ();
            theFlowParent    = flowParent;
            transform.parent = flowParent.transform;

            //Initiate flow movement and informations for water control
            flowMovement.InitFlow(targetFlow, targetPercentage, upDirection);
            waterControl.InitFlow(targetFlow);
            currentFlow = targetFlow;

            //Switch to inFlow mode
            FlowMode(true);
            PlayerController.inFlow       = true;
            PlayerController.controlsAble = true;
            sW.LoseSeaWeeds();
        }
    }