Ejemplo n.º 1
0
    void setThrowable(float horizontal, float vertical)
    {
        if (throwable_letter != "")
        {
            float stickRotation;
            float orientation = Mathf.Sign(transform.localScale.x);
            if (Mathf.Abs(horizontal) + Mathf.Abs(vertical) > 0.5f)
            {
                //we will be making changes to the angle
                Vector3 directionalVector = new Vector3(horizontal, vertical);
                stickRotation = Vector3.Angle(Vector3.right, directionalVector);
                //getting the cross product will tell us whether we are going clockwise or ccw
                //if it's ccw, we set it to -angle
                Vector3 cross = Vector3.Cross(Vector3.right, directionalVector);
                if (cross.z < 0)
                {
                    stickRotation *= -1;
                }

                if (horizontal > 0)
                {
                    transform.localScale = new Vector3(-Mathf.Abs(transform.localScale.x), transform.localScale.y, transform.localScale.z);
                }
                else if (horizontal < 0)
                {
                    transform.localScale = new Vector3(Mathf.Abs(transform.localScale.x), transform.localScale.y, transform.localScale.z);
                }

                float previousangle = throwable_angle;
                float newAngle      = stickRotation + 180;
                //float newAngle = GameManager.vectorToAngle(Throwable.ComputeTrajectoryAngle(stickRotation+180));

                if (throwable == null)
                {
                    //set the new throwable angle
                    throwable_angle = newAngle;

                    //spawn new
                    createThrowable(throwable_letter, true);
                }
                else if ((Mathf.Abs(newAngle - throwable_angle) > 20f && (Time.time - throwable.LaunchTime) > 0.5f) || orientation != Mathf.Sign(transform.localScale.x))
                {
                    //set the new throwable angle
                    throwable_angle = newAngle;

                    //destroy current
                    DestroyImmediate(throwable.gameObject);

                    //spawn new
                    createThrowable(throwable_letter, true);
                }
                else
                {
                    //it's not null and a new one is not getting created
                    throwable.AdjustTrailIfTrace(transform.position);
                }
            }
            else if (Mathf.Abs(horizontal) + Mathf.Abs(vertical) < 0.1f)
            {
                if (throwable != null)
                {
                    //destroy current
                    DestroyImmediate(throwable.gameObject);
                }
            }
        }
    }