예제 #1
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());
        }
    }
예제 #2
0
 virtual protected void FaceTarget()
 {
     if (target != null)
     {
         float targetAngle = EssoUtility.GetAngleFromVector((target.position - transform.position).normalized);
         /* targetAngle += 90f;*/                                                                                          // turn offset -Due to converting between forward vector and up vector
                                                                                                                           //if (targetAngle < 0) targetAngle += 360f;
         float angle = Mathf.SmoothDampAngle(transform.eulerAngles.z, targetAngle, ref smoothRot, settings.rotationSpeed); //rotate player smoothly to target angle
         transform.rotation = Quaternion.Euler(0f, 0f, angle);                                                             //update angle
         //fovObject.SetAimDirection((-1)*fovObject.GetVectorFromAngle(angle));
     }
 }
예제 #3
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);
    }
예제 #4
0
    virtual protected void FaceMovementDirection(Vector2 dir)
    {
        float targetAngle = EssoUtility.GetAngleFromVector((dir.normalized));

        /// turn offset -Due to converting between forward vector and up vector
        if (targetAngle < 0)
        {
            targetAngle += 360f;
        }
        float angle = Mathf.SmoothDampAngle(transform.eulerAngles.z, targetAngle, ref smoothRot, settings.rotationSpeed); //rotate player smoothly to target angle

        transform.rotation = Quaternion.Euler(0f, 0f, angle);                                                             //update angle
        //fovObject.SetAimDirection((-1)*fovObject.GetVectorFromAngle(angle));
    }
예제 #5
0
 //Sets the starting angle to direction of given vector
 public void SetAimDirection(Vector3 aimDir)
 {
     startingAngle = (EssoUtility.GetAngleFromVector(aimDir) - fovAngle / 2);
 }