예제 #1
0
    private void DoShoot()
    {
        BounceRay hit = BounceRay.Cast(playerController.transform.position, gmousePos - playerController.transform.position, 10.0f, LayerMask.GetMask("Bounceable"), LayerMask.GetMask("Actor"));

        hitPoints = hit.endPoints;

        Vector2 prevPoint = playerController.transform.position;

        int visorIndex = 0;

        foreach (Vector2 endPoint in hit.endPoints)
        {
            int count = Mathf.FloorToInt((endPoint - prevPoint).magnitude / 0.1f);

            for (int i = 0; i < count; i++)
            {
                visors[visorIndex].transform.position = Vector2.Lerp(prevPoint, endPoint, (float)i / count);
                visorIndex++;
            }

            for (int i = visorIndex; i < 100; i++)
            {
                visors[i].transform.position = new Vector3(1000, 1000, 0);
            }

            prevPoint = endPoint;
        }
    }
예제 #2
0
    public List <HitPackage> Shoot(bool justDraw = false)
    {
        if (!shootingCooldown.IsOver())
        {
            return(null);  // TODO: aca podria indicarle al usuario que no puede disparar todavia (o mostrar en la UI el remaining cooldown)
        }
        shootingCooldown.RestartCooldown();

        Debug.Log($"shooting {shootingCooldown.RemainingCooldown()}");

        // Draw bullet
        var _transform = GO.transform;
        var bullet     = new Bullet(_transform.position, _transform.forward, _transform.rotation);

        bullet.Cast();
        if (justDraw)
        {
            return(null);
        }

        // Calculate bullet's bounces
        Vector3 originRay = _transform.position + _transform.forward * 0.6f;
        var     bounceRay = BounceRay.Cast(originRay, _transform.forward, gunRange);

        if (bounceRay.contacts.Count != 0)
        {
            var hitPackages = new List <HitPackage>();
            bounceRay.contacts.ForEach(c =>
            {
                hitPackages.Add(new HitPackage(c.transform.name, gunDamage));
                Debug.Log($"shot {c.transform.name}");
            });
            return(hitPackages);
        }

        // Old single ray implementation
        // RaycastHit hit;
        // var ray = new Ray(originRay, _transform.forward);
        // if (Physics.Raycast(ray, out hit, gunRange))
        // {
        //     Debug.Log($"shot {hit.transform.name}");
        //     return new HitPackage(hit.transform.name, gunDamage);
        // }

        return(null);
    }
예제 #3
0
    private IEnumerator ShootRoutine()
    {
        playerController.controllable = false;
        customCursor.active           = false;

        Vignette vignette = postProcessProfile.GetSetting <Vignette>();

        breath.PlayOneShot(breaths[Random.Range(0, breaths.Count - 1)]);



        float currTime = 0.0f;

        while (currTime < 0.8f)
        {
            float progress = currTime / 0.8f;

            //mainTrack.pitch = EaseOutQuad(1.0f, 0.5f, progress);
            float freq = EaseOutQuad(22000.0f, 600.0f, progress);
            mainTrackLowPass.cutoffFrequency = freq;
            foreach (AudioLowPassFilter audioSource in lowPassLayers)
            {
                audioSource.cutoffFrequency = freq;
            }


            rainLowPass.cutoffFrequency = EaseOutQuad(22000.0f, 600.0f, progress);
            Time.timeScale = EaseOutQuad(1.0f, 0.1f, progress);
            vignette.intensity.Override(EaseOutQuad(0.1f, 0.3f, progress));

            foreach (SpriteRenderer visor in visors)
            {
                visor.color = Color32.Lerp(new Color32(255, 255, 255, 255), new Color32(255, 255, 255, 0), progress);
            }

            currTime += Time.unscaledDeltaTime;

            yield return(null);
        }
        mainTrackLowPass.cutoffFrequency = 600.0f;
        foreach (AudioLowPassFilter audioSource in lowPassLayers)
        {
            audioSource.cutoffFrequency = 600.0f;
        }
        rainLowPass.cutoffFrequency = 600.0f;
        //mainTrack.pitch = 0.5f;
        Time.timeScale = 0.1f;
        vignette.intensity.Override(0.3f);
        foreach (SpriteRenderer visor in visors)
        {
            visor.color = new Color32(255, 255, 255, 0);
        }

        BounceRay hit = BounceRay.Cast(playerController.transform.position, gmousePos - playerController.transform.position, 10.0f, LayerMask.GetMask("Bounceable"), LayerMask.GetMask("Actor"));

        hitPoints = hit.endPoints;

        targetActor = null;
        if (hit.hit != null && ((RaycastHit2D)hit.hit).collider != null)
        {
            Actor actor = ((RaycastHit2D)hit.hit).collider.GetComponent <Actor>();
            targetActor = actor;

            if (targetActor.isTarget)
            {
                wasHit = true;
            }
        }

        gunshot.Play();
        bullet         = Instantiate(bulletPrefab, playerController.transform.position, Quaternion.identity);
        bulletParticle = Instantiate(bulletParticlePrefab, playerController.transform.position, Quaternion.identity);

        StartCoroutine(BulletKill());

        yield return(StartCoroutine(Delay(0.2f, true)));

        currTime = 0.0f;
        while (currTime < 0.5f)
        {
            float progress = currTime / 0.5f;


            //mainTrack.pitch = EaseOutQuad(0.5f, 1.0f, progress);
            float freq = EaseOutQuad(600.0f, 22000.0f, progress);
            mainTrackLowPass.cutoffFrequency = freq;
            foreach (AudioLowPassFilter audioSource in lowPassLayers)
            {
                audioSource.cutoffFrequency = freq;
            }
            rainLowPass.cutoffFrequency = EaseOutQuad(600.0f, 22000.0f, progress);
            Time.timeScale = EaseOutQuad(0.1f, 1.0f, progress);
            vignette.intensity.Override(EaseOutQuad(0.3f, 0.1f, progress));

            currTime += Time.unscaledDeltaTime;

            yield return(null);
        }
        mainTrackLowPass.cutoffFrequency = 22000.0f;
        foreach (AudioLowPassFilter audioSource in lowPassLayers)
        {
            audioSource.cutoffFrequency = 22000.0f;
        }
        rainLowPass.cutoffFrequency = 22000.0f;
        //mainTrack.pitch = 1.0f;
        Time.timeScale = 1.0f;
        vignette.intensity.Override(0.1f);
    }
예제 #4
0
    // Returns all contact points from a bouncing ray at the specified position and moving in the specified direction.
    public static BounceRay Cast(Vector2 position, Vector2 direction, float magnitude, int bounceMask, int layerMask)
    {
        // Initialize the return data.
        BounceRay bounceRay = new BounceRay
        {
            contacts       = new List <RaycastHit2D>(),
            endPoints      = new List <Vector2>(),
            finalDirection = direction.normalized
        };

        // If there is magnitude left...
        if (magnitude > 0)
        {
            // Fire out initial vector.
            RaycastHit2D bounceHit = Physics2D.Raycast(position, direction, magnitude, bounceMask);
            RaycastHit2D hit       = Physics2D.Raycast(position, direction, magnitude, layerMask);

            Collider2D hitCollider = hit.collider;

            if (bounceHit.distance > 0 && hit.distance > 0 && bounceHit.distance < hit.distance)
            {
                hitCollider = null;
            }

            if (hitCollider != null)
            {
                bounceRay.hit = hit;
            }

            // Calculate our bounce conditions.
            bool hitSucceeded       = bounceHit.collider != null && bounceHit.distance > 0;
            bool magnitudeRemaining = bounceHit.distance < magnitude;

            Vector2 finalPosition = Vector2.zero;
            // Get the final position.
            if (hitCollider != null)
            {
                finalPosition = hit.point;
            }
            else
            {
                finalPosition = hitSucceeded ? bounceHit.point : position + direction.normalized * magnitude;
            }

            // Draw final position.
            Debug.DrawLine(position, finalPosition, Color.green);

            // If the bounce conditions are met, add another bounce.
            if (hitSucceeded && magnitudeRemaining && bounceRay.hit == null)
            {
                // Add the contact and hit point of the raycast to the BounceRay.
                bounceRay.contacts.Add(bounceHit);
                bounceRay.endPoints.Add(bounceHit.point);

                // Reflect the hit.
                Vector2 reflection = Vector2.Reflect((bounceHit.point - position).normalized, bounceHit.normal);

                // Create the reflection vector
                Vector2 reflectionVector = reflection;

                // Bounce the ray.
                BounceRay bounce = Cast(
                    bounceHit.point + bounceHit.normal / 1000.0f,
                    reflectionVector,
                    magnitude - bounceHit.distance,
                    bounceMask,
                    layerMask);

                // Include the bounce contacts and origins.
                bounceRay.contacts.AddRange(bounce.contacts);
                bounceRay.endPoints.AddRange(bounce.endPoints);

                // Set the final direction to what our BounceRay call returned.
                bounceRay.finalDirection = bounce.finalDirection;

                // We've bounced if we are adding more contact points and origins.
                bounceRay.bounced = true;

                if (hitCollider == null)
                {
                    bounceRay.hit = bounce.hit;
                }
            }
            else
            {
                // Add the final position if there is no more magnitude left to cover.
                bounceRay.endPoints.Add(finalPosition);
                bounceRay.finalDirection = direction;
            }
        }

        // Return the current position & direction as final.
        return(bounceRay);
    }
예제 #5
0
    // Returns all contact points from a bouncing ray at the specified position and moving in the specified direction.
    public static BounceRay Cast(Vector3 position, Vector3 direction, float magnitude)
    {
        // Initialize the return data.
        BounceRay bounceRay = new BounceRay
        {
            contacts       = new List <RaycastHit>(),
            endPoints      = new List <Vector3>(),
            finalDirection = direction.normalized
        };

        // If there is magnitude left...
        if (magnitude > 0)
        {
            Ray ray = new Ray(position, direction);

            // Fire out initial vector.
            RaycastHit hit;

            // Calculate our bounce conditions.
            bool hitSucceeded       = Physics.Raycast(ray, out hit, magnitude);
            bool magnitudeRemaining = hit.distance < magnitude;

            // Get the final position.
            Vector3 finalPosition = hitSucceeded ? hit.point : position + direction.normalized * magnitude;

            // Draw final position.
            Debug.DrawLine(position, finalPosition, Color.green);

            // If the bounce conditions are met, add another bounce.
            if (hitSucceeded && magnitudeRemaining)
            {
                // Add the contact and hit point of the raycast to the BounceRay.
                bounceRay.contacts.Add(hit);
                bounceRay.endPoints.Add(hit.point);

                // Reflect the hit.
                Vector3 reflection = Vector3.Reflect((hit.point - position).normalized, hit.normal);

                // Create the reflection vector
                Vector3 reflectionVector = reflection;

                // Bounce the ray.
                BounceRay bounce = Cast(
                    hit.point,
                    reflectionVector,
                    magnitude - hit.distance);

                // Include the bounce contacts and origins.
                bounceRay.contacts.AddRange(bounce.contacts);
                bounceRay.endPoints.AddRange(bounce.endPoints);

                // Set the final direction to what our BounceRay call returned.
                bounceRay.finalDirection = bounce.finalDirection;

                // We've bounced if we are adding more contact points and origins.
                bounceRay.bounced = true;
            }
            else
            {
                // Add the final position if there is no more magnitude left to cover.
                bounceRay.endPoints.Add(finalPosition);
                bounceRay.finalDirection = direction;
            }
        }

        // Return the current position & direction as final.
        return(bounceRay);
    }