Ejemplo n.º 1
0
    private void Update()
    {
        //Au moment où on appuie pour dash, on ralentit le joueur
        if (Input.GetButtonDown("Fire1") && !dashing && dashCapacity > 0 && hasControl)
        {
            firstMousePosition = Input.mousePosition;
            StartCoroutine(WaitBeforeDashDeceleration(0.5f));
            //DashDrawer.ClearLine(dashLine);
        }
        //Dessine une ligne tant que le bouton est appuyé
        if (Input.GetButton("Fire1") && preparingDash)
        {
            Vector3 newMousePos = Input.mousePosition;
            //Debug.Log("First mouse pos : " + firstMousePosition);
            //Debug.Log("newMousePos : " + newMousePos);
            //Debug.Log(firstMousePosition - newMousePos);
            DashDrawer.DrawLine(dashLine, transform.position - (firstMousePosition - newMousePos) / 100, transform.position, Color.black, 0.15f);
            DashDrawer.DrawTajectoryLine(trajectoryLine, Color.white, transform.position, 100, (firstMousePosition - newMousePos) / 50f);
        }

        if (Input.GetButtonUp("Fire1") && preparingDash)
        {
            //if (dashAcceleration != Vector2.zero && dashAcceleration != null)
            //{
            preparingDash = false;
            StartCoroutine(WaitBeforeLineFaded(0.1f, dashLine.GetPosition(0) - dashLine.GetPosition(1)));
            //}
            StartCoroutine(DashDrawer.FadeLine(dashLine, 0.1f));
            StopCoroutine(DashDrawer.FadeLine(dashLine, 0.1f));
            DashDrawer.ClearLine(trajectoryLine);
        }
    }
Ejemplo n.º 2
0
    IEnumerator WaitBeforeDashDeceleration(float dashDecelerationTime)
    {
        Vector2 oldVelocity = rb2D.velocity;

        preparingDash = true;
        float timer     = 0f;
        float lerpValue = 0;

        while (lerpValue <= 1f && preparingDash)
        {
            rb2D.velocity = Vector2.Lerp(oldVelocity, Vector2.zero, lerpValue);
            lerpValue    += Time.deltaTime;
            yield return(new WaitForSeconds(dashDecelerationTime * Time.deltaTime));

            timer += dashDecelerationTime * Time.deltaTime;
            //Debug.Log("Velocity dash :" + rb2D.velocity);
        }
        timer = 0f;
        //S'il prepare encore son dash
        while (preparingDash && timer < prepareDashTime)
        {
            yield return(new WaitForSeconds(Time.deltaTime));

            if (preparingDash)
            {
                rb2D.velocity = Vector2.zero;
            }
            timer += Time.deltaTime;
        }
        if (timer >= prepareDashTime)
        {
            DashDrawer.ClearLine(trajectoryLine);
            Debug.Log(preparingDash);
            preparingDash = false;
            StartCoroutine(DashDrawer.FadeLine(dashLine, 0.3f));
            StopCoroutine(DashDrawer.FadeLine(dashLine, 0.3f));
        }

        dashAcceleration = CalculateAcceleration(oldVelocity, rb2D.velocity, timer);

        StopCoroutine(WaitBeforeDashDeceleration(dashDecelerationTime));
    }