Пример #1
0
        IEnumerator pullWhale()
        {
            float waitTime = waitTImebfrPull;

            rope.enabled = true;
            rope.SetPosition(1, ProjectilePoint.InverseTransformPoint(targetWhale.transform.position));

            while (waitTime > 0 && whaleInRange)
            {
                waitTime -= Time.deltaTime;
                yield return(null);
            }
            if (whaleInRange)
            {
                float pullTime = Vector3.Distance(targetWhale.transform.position, ProjectilePoint.position) / tieWhaleSpeed;
                while (pullTime > 0 && whaleInRange)
                {
                    pullTime -= Time.deltaTime;
                    Vector3 newPos = Vector3.MoveTowards(targetWhale.transform.position, ProjectilePoint.position, Time.deltaTime * tieWhaleSpeed);
                    newPos.y = targetWhale.transform.position.y;
                    targetWhale.transform.position = newPos;
                    rope.SetPosition(1, ProjectilePoint.InverseTransformPoint(targetWhale.transform.position));
                    yield return(null);
                }
                if (whaleInRange)
                {
                    TieWhale();
                }
            }
            rope.enabled = false;
        }
Пример #2
0
 void Start()
 {
     base.Start();
     projectilePool = PoolManager.instance.HarpoonPool;
     shipLayer      = LayerMask.GetMask("Ship");
     rope           = ProjectilePoint.GetComponent <LineRenderer>();
     rope.enabled   = false;
 }
Пример #3
0
    public List <ProjectilePoint> GetProjectileSamples(Vector2 initialPos2D, Vector2 targetPos2D, bool normalized = false)
    {
        float currentProjectileSpentTime = 0;
        float overalTime   = 0;
        float timeInterval = Time.deltaTime;

        Vector2 initialPos2D1 = initialPos2D;
        Vector2 initialPos2D2 = initialPos2D;

        float totalDistance       = Vector2.Distance(targetPos2D, initialPos2D1);
        float projectileDistance1 = (totalDistance * this.ratio) * 2;
        float projectileDistance2 = (totalDistance - projectileDistance1 / 2) * 2;

        initialPos2D2.x += ((projectileDistance1 / 2) - projectileDistance2 / 2);

        float duration1 = this.duration * this.ratio * 2;
        float duration2 = this.duration * (1 - this.ratio) * 2;

        this.gravity1         = CalculateGravity(projectileDistance1, duration1, this.initialAngle1);
        this.initialVelocity1 = CalculateVelocity(projectileDistance1, duration1, this.initialAngle1);

        this.height = 0.5f * this.gravity1 * Mathf.Pow(duration1 / 2, 2) +
                      this.initialVelocity1 * Mathf.Sin(Mathf.Deg2Rad * this.initialAngle1) * duration1 / 2 +
                      initialPos2D1.y;

        Vector2 midPos = GetPosition(duration1 / 2, this.initialVelocity1, this.initialAngle1, initialPos2D1, this.gravity1);

        this.gravity2         = -8 * (midPos.y - initialPos2D2.y) / (float)Mathf.Pow(duration2, 2);
        this.initialAngle2    = Mathf.Rad2Deg * Mathf.Atan(4 * (midPos.y - initialPos2D2.y) / projectileDistance2);
        this.initialVelocity2 = (-gravity2 * duration2) / (2 * Mathf.Sin(Mathf.Deg2Rad * initialAngle2));

        this.rotationAngle = GetRotateAngle(initialPos2D1, targetPos2D);
        this.rotationPivot = initialPos2D1;

        List <ProjectilePoint> projectilePoints = new List <ProjectilePoint>();

        int count1 = (int)(this.duration * ratio / Time.deltaTime);

        for (int i = 0; i < count1; i++)
        {
            Vector3 currentPos = GetPosition(currentProjectileSpentTime, this.initialVelocity1, this.initialAngle1, initialPos2D1, this.gravity1);
            projectilePoints.Add(new ProjectilePoint(overalTime, RotatePointAroundPivot(currentPos, rotationPivot, new Vector3(0, 0, rotationAngle)), 0));

            currentProjectileSpentTime += timeInterval;
            overalTime += timeInterval;
        }

        currentProjectileSpentTime = this.duration * (1 - ratio);

        int count2 = (int)((this.duration - overalTime) / Time.deltaTime);

        for (int i = 0; i < count2; i++)
        {
            currentProjectileSpentTime += timeInterval;
            overalTime += timeInterval;
            Vector3 currentPos = GetPosition(currentProjectileSpentTime, this.initialVelocity2, this.initialAngle2,
                                             initialPos2D2, this.gravity2);

            projectilePoints.Add(new ProjectilePoint(overalTime,
                                                     RotatePointAroundPivot(currentPos, rotationPivot, new Vector3(0, 0, rotationAngle)), 1));
        }

        if (normalized)
        {
            for (var index = 0; index < projectilePoints.Count; index++)
            {
                ProjectilePoint pointPair      = projectilePoints[index];
                Vector2         currentPos     = pointPair.Position2D;
                Vector2         normCurrentPos = new Vector2(currentPos.x / totalDistance, currentPos.y / this.height);
                pointPair.Position2D    = RotatePointAroundPivot(normCurrentPos, rotationPivot, new Vector3(0, 0, rotationAngle));
                projectilePoints[index] = new ProjectilePoint(pointPair.TimeStamp, pointPair.Position2D, pointPair.ProjectileId);
            }
        }

        return(projectilePoints);
    }
Пример #4
0
 // Use this for initialization
 void Start()
 {
     base.Start();
     projectilePoints = ProjectilePoint.GetComponentsInChildren <Transform>();
 }