Exemplo n.º 1
0
        private void DrawTrajectory()
        {
            if (currentArrow)
            {
                Vector3 initialVelocity = PhysicsCalcUtil.CalcInitVelocity(currentArrow.transform.position,
                                                                           targetPosition, hDisplacement, Physics.gravity.y).initialVelocity;

                Vector3 arrowRotationCompensator = currentArrow.transform.forward / 2;
                initialVelocity = initialVelocity - arrowRotationCompensator;
                trajectoryRenderer.ShowTrajectory(currentArrow.transform.position, initialVelocity);
            }
        }
Exemplo n.º 2
0
        private void Launch()
        {
            if (currentArrow != null)
            {
                Vector3 startForce = PhysicsCalcUtil.CalcInitVelocity(currentArrow.transform.position,
                                                                      targetPosition, hDisplacement, Physics.gravity.y).initialVelocity;

                currentArrow.Init(startForce, damage);

                currentArrow = null;

                StartCoroutine(SetTimeout(reloadTime, () =>
                {
                    currentArrow = Instantiate(arrowPrefab, arrowPosition.transform.position, arrowPosition.transform.rotation, arrowPosition.transform);
                }));
            }
        }
Exemplo n.º 3
0
        private void HandleBowRotation()
        {
            if (!currentArrow)
            {
                return;
            }

            Vector3 initialVelocity = PhysicsCalcUtil.CalcInitVelocity(currentArrow.transform.position,
                                                                       targetPosition, hDisplacement, Physics.gravity.y).initialVelocity;

            // simulate first step of arrow movement
            Vector3 startOfParabola = currentArrow.transform.position + initialVelocity * Time.fixedDeltaTime +
                                      Physics.gravity * (Time.fixedDeltaTime * Time.fixedDeltaTime) / 2f;
            // find direction
            Vector3 lookDirection = startOfParabola - currentArrow.transform.position;

            // calc rotation
            bow.transform.forward          = lookDirection;
            bow.transform.localEulerAngles = bow.transform.localEulerAngles.With(y: 0, z: 0);
        }