예제 #1
0
    IEnumerator MoveProjectile(Vector3 start, ShipEntity target, bool hit)
    {
        GameObject projectile = Object.Instantiate(base.shotVFX, start, Quaternion.identity, null);
        Vector3    miss       = target.transform.position + Random.onUnitSphere * 10f;
        Vector3    hitpos     = target.transform.position + (base.owner.transform.position - target.transform.position).normalized * (2 + (int)target.ship.size);

        float d  = Vector3.Distance(start, target.transform.position);
        float tt = d / base.speed;
        float t  = 0f;

        while (t <= tt && target != null)
        {
            t += Time.deltaTime;

            hitpos = target.transform.position + (start - target.transform.position).normalized * (2 + (int)target.ship.size);
            projectile.transform.position = Vector3.Lerp(start, hit ? hitpos : miss, t / tt);
            projectile.transform.LookAt(hit ? target.transform.position : miss);
            yield return(null);
        }

        if (target != null)
        {
            if (hit)
            {
                base.SpawnShieldVFX(-projectile.transform.forward.normalized, hitpos, target);
                target.ApplyDamage(base.GetDamage());
            }
        }

        Object.Destroy(Object.Instantiate(detonationVFX, projectile.transform.position, Random.rotation, null), 3f);
        Object.Destroy(projectile);
    }
예제 #2
0
    IEnumerator MoveMissile(Vector3 start, ShipEntity target)
    {
        GameObject missile = Object.Instantiate(base.shotVFX, start, Quaternion.identity, null);

        float t = 0f;

        while (t <= _lifetime && target != null)
        {
            if (Vector3.Distance(missile.transform.position, target.transform.position) <= 1f)
            {
                Vector3 hitpos = (missile.transform.position - target.transform.position).normalized;
                base.SpawnShieldVFX(hitpos, hitpos * 5f, target);
                target.ApplyDamage(GetDamage());
                break;
            }

            t += Time.deltaTime;
            missile.transform.position = Vector3.Lerp(start, target.transform.position, t / _lifetime);
            missile.transform.LookAt(Vector3.Lerp(start, target.transform.position, (t + .1f) / _lifetime));
            yield return(null);
        }

        Object.Destroy(Object.Instantiate(base.detonationVFX, missile.transform.position, Random.rotation, null), 3f);
        Object.Destroy(missile);
    }