Ejemplo n.º 1
0
    //Update light shape
    private void SetShapeOfLight()
    {
        Debug.Log("running in light");
        currentAngle = startingAngle + offset;
        float angleIncrease = fovAngle / lightPathPoints.Length;

        for (int i = 0; i < lightPathPoints.Length; i++)
        {
            if (i > 0)
            {
                RaycastHit2D hitInfo = Physics2D.Raycast(origin, EssoUtility.GetVectorFromAngle(currentAngle), viewDistance, ViewBlockingLayers);
                if (hitInfo)
                {
                    lightPathPoints[i] = hitInfo.point;
                    Debug.DrawLine(lightPathPoints[0], hitInfo.point);
                }
                else
                {
                    lightPathPoints[i] = origin + EssoUtility.GetVectorFromAngle(currentAngle) * viewDistance;
                    Debug.DrawRay(lightPathPoints[0], lightPathPoints[0] + EssoUtility.GetVectorFromAngle(currentAngle) * viewDistance);
                }
            }
            else
            {
                lightPathPoints[i] = origin;
            }


            currentAngle -= angleIncrease;
        }
        for (int i = 0; i < lightCone.shapePath.Length; i++)
        {
            lightCone.shapePath[i] = lightPathPoints[i];
        }
    }
Ejemplo n.º 2
0
    private IEnumerator CheckCollision()
    {
        netForce     = Vector2.zero;
        currentAngle = (EssoUtility.GetAngleFromVector(transform.right) - detectionArcAngle / 2) + 90;
        for (int i = 0; i < rayCount; i++)
        {
            Vector2 point;
            //Using utility function to convert a angle into a vector
            RaycastHit2D hitInfo = Physics2D.Raycast(transform.position, EssoUtility.GetVectorFromAngle(currentAngle), detectionRadius, detectionLayers);
            if (hitInfo)
            {
                //If it hits something the current vertex position = point
                point = hitInfo.point;
                AvoidPoint(point);
            }
            else
            {
                //If not just draw full length of ray in current angle
                point = transform.position + EssoUtility.GetVectorFromAngle(currentAngle) * detectionRadius;
            }
            Debug.DrawLine(transform.position, point, Color.green, 0.5f);
            currentAngle -= angleBetweenRays;
        }

        yield return(new WaitForSeconds(tickRate));

        if (isActive)
        {
            StartCoroutine(CheckCollision());
        }
    }
Ejemplo n.º 3
0
    virtual protected void DrawVisionConeShape()
    {
        //Create then number of total vertices required
        Vector3[] vertices = new Vector3[rayCount + 1 + 1];//orgin ray + ray 0

        //Create UVs to all vertices
        Vector2[] uv = new Vector2[vertices.Length];

        //D
        int[] triangles = new int[rayCount * 3];   //for every ray there should  be triangle and as the triangle has three vertices ray*3

        currentAngle = startingAngle + offset;     //Adds offset to angle player straight on
        float angleIncrease = fovAngle / rayCount; //The incremenent for each angle

        vertices[0] = origin;                      // first vertex should alwaus be at the index

        int vertexIndex   = 1;                     //start at index one  (second element)
        int triangleIndex = 0;

        for (int i = 0; i < rayCount; i++)
        {
            Vector3 vertex;
            //Using utility function to convert a angle into a vector
            RaycastHit2D hitInfo = Physics2D.Raycast(origin, EssoUtility.GetVectorFromAngle(currentAngle), viewDistance, ViewBlockingLayers);
            if (hitInfo)
            {
                //If it hits something the current vertex position = point
                vertex = hitInfo.point;
            }
            else
            {
                //If not just draw full length of ray in current angle
                vertex = origin + EssoUtility.GetVectorFromAngle(currentAngle) * viewDistance;
            }
            vertices[vertexIndex] = vertex;
            if (i > 0)//Do not do it for the first element as it is the origin
            {
                triangles[triangleIndex + 0] = 0;
                triangles[triangleIndex + 1] = vertexIndex - 1;
                triangles[triangleIndex + 2] = vertexIndex;
                triangleIndex += 3;
            }

            vertexIndex++;
            currentAngle -= angleIncrease;
        }

        //Update mesh
        mesh.vertices  = vertices;
        mesh.uv        = uv;
        mesh.triangles = triangles;
        mesh.bounds    = new Bounds(origin, Vector3.one * 1000f);//Sets bounds to size of map
    }
Ejemplo n.º 4
0
 public void EjectSpawnEgg()
 {
     if (enemyCount < maxAttackCount)
     {
         if (gameObject.activeInHierarchy && aSource)
         {
             aSource.Play();
         }
         EggSpawner egg           = ObjectPoolManager.Spawn(eggSpawnerPrefab, transform.position, Quaternion.identity);
         Vector2    randDirection = EssoUtility.GetVectorFromAngle(Random.Range(0f, 360f));
         egg.EjectEgg(ejectForce, randDirection);
         egg.SetUpEgg(playerTransform, GetRandomEnemyFromList(), this);
     }
 }
Ejemplo n.º 5
0
    private Vector3[] GetVectorsInArc()
    {
        Vector3[] shotDir = new Vector3[bulletsPerShot];

        for (int i = 0; i < shotDir.Length; i++)
        {
            float startingAngle = (EssoUtility.GetAngleFromVector(firePoint.up) - sprayRange / 2);
            float randOffset    = Random.Range(-spray, spray);

            shotDir[i] = EssoUtility.GetVectorFromAngle(randOffset + startingAngle + sprayRange);
        }

        return(shotDir);
    }
Ejemplo n.º 6
0
    public void SpawnFragments()
    {
        float      angleIncrement = 360f / fragmentCounts;
        float      currentAngle   = 0f;
        GameObject currentFragment;

        for (int i = 0; i < fragmentCounts; i++)
        {
            int rand = Random.Range(0, slimeFragmentsPrefabs.Count);
            currentFragment = ObjectPoolManager.Spawn(slimeFragmentsPrefabs[rand], transform.position);

            Vector3 dir = EssoUtility.GetVectorFromAngle(currentAngle).normalized;
            currentFragment.transform.up = dir;
            IShootable frag = currentFragment.GetComponent <IShootable>();
            frag.SetUpBullet(knockBack / fragmentCounts, damage / fragmentCounts);
            frag.Shoot(dir, shotForce * 0.8f);
            currentAngle += angleIncrement;
        }
    }
Ejemplo n.º 7
0
    protected void WeakenEnemy()
    {
        currentAngle = startingAngle + offset;     //Adds offset to angle player straight on
        float angleIncrease = fovAngle / rayCount; //The incremenent for each angle

        for (int i = 0; i < rayCount; i++)
        {
            RaycastHit2D hitInfo = Physics2D.Raycast(origin, EssoUtility.GetVectorFromAngle(currentAngle), viewDistance, enemyLayer);

            if (hitInfo)
            {
                if (hitInfo.transform.GetComponent <ILightWeakness>() != null)
                {
                    hitInfo.transform.GetComponent <ILightWeakness>().MakeVulnerable();
                }
                Debug.DrawRay(origin, hitInfo.point);
            }
            else
            {
                Debug.DrawRay(origin, EssoUtility.GetVectorFromAngle(currentAngle) * viewDistance);
            }
            currentAngle -= angleIncrease;
        }
    }