Пример #1
0
    public void OnUp(float angleY, float angleZ)
    {
        Vector3 initialVelocity = ballMovement.CalculateInitialVelocity(angleY, angleZ, targetPlatform.Position);

        projectilePathDrawer.RemovePath();
        ballMovement.Launch(initialVelocity);
        launched = true;
    }
Пример #2
0
    private void Update()
    {
        if (ball == null)
        {
            ball      = FindObjectOfType <BallMovement>();
            canLaunch = true;
        }

        if (Time.timeScale < 1f)
        {
            isGameActive = false;
        }
        else
        {
            StartCoroutine(GameActive());
        }

        if (isGameActive)
        {
            if (Input.GetMouseButton(0))
            {
                Ray ray = mainCamera.ScreenPointToRay(Input.mousePosition);
                arrowDistance = Vector3.Distance(lookAt.position, transform.position);
                if (Physics.Raycast(ray, out RaycastHit raycastHit, float.MaxValue, layerMask))
                {
                    Vector3 point = raycastHit.point;
                    point.z            = Mathf.Clamp(point.z, -4, 4);
                    point.x            = Mathf.Clamp(point.x, 5, 9.5f);
                    point.y            = 0;
                    transform.position = point;
                    transform.LookAt(lookAt);

                    if (canLaunch)
                    {
                        image.SetActive(true);
                        image.transform.localScale = new Vector3(arrowDistance / 5.5f, 0.15f, 1f);
                    }
                }
            }
            if (Input.GetMouseButtonUp(0))
            {
                Vector3 dir = (lookAt.position - transform.position).normalized;
                currDistance       = Vector3.Distance(lookAt.position, transform.position);
                transform.position = transform.position + (dir * (currDistance - 1f));

                image.SetActive(false);
                if (canLaunch)
                {
                    ball.Launch(dir, currDistance);
                    canLaunch = false;
                }
            }
        }
    }
Пример #3
0
    //capture time and position of the end of the drag
    //based on beginning and end of the drag calculate the velocity of the drag and call launching of the ball
    public void DragStop()
    {
        dragTimeEnd     = Time.time;
        dragTime        = dragTimeEnd - dragTimeStart;
        dragEndPosition = Input.mousePosition;

        dragLength = dragEndPosition - dragStartPosition;
        float dragInZ = dragEndPosition.y;

        dragVelocity = new Vector3(dragLength.x, 0f, dragInZ) / dragTime;

        ball.Launch(dragVelocity);
    }
    public void DragEnd()
    {
        //Launch the ball;
        if (!ball.isPlay)
        {
            endTime = Time.time;
            dragEnd = Input.mousePosition;

            float dragDuration = endTime - startTime;

            float launchSpeedX = (dragEnd.x - dragStart.x) / dragDuration;
            float launchSpeedZ = (dragEnd.y - dragStart.y) / dragDuration;

            Vector3 launchVelocity = new Vector3(launchSpeedX, 0, launchSpeedZ);

            ball.Launch(launchVelocity);
        }
    }
Пример #5
0
 private void LauchBall()
 {
     _ball.transform.parent = null;
     _ball.Launch(_arrowDirection);
     _ball = null;
 }