public CentipedePoint getRandomPath(CentipedePoint t)
    {
        CentipedePoint randomPoint;

        do
        {
            randomPoint = possibleWays[Random.Range(0, possibleWays.Length)];
        } while (randomPoint.Equals(t));
        return(randomPoint);
    }
Example #2
0
    public void createFixedHead(Transform nPos)
    {
        this.transform.position = nPos.position;
        CentipedePoint nearestPoint = Util.getNearestTarget(transform, points);

        this.nextTarget = nearestPoint.getRandomPath(nearestPoint);
        this.lastTarget = nextTarget;
        rotate(nextTarget.transform);
        fixedHead = true;
    }
Example #3
0
 public override void manageMovement()
 {
     rb.MovePosition(Vector2.MoveTowards(transform.position, nextTarget.transform.position, (speed * CurseManager.enemiesSpeed) * Time.deltaTime));
     if (Vector2.Distance(transform.position, nextTarget.transform.position) < 0.2f || collidingStaticObject)
     {
         CentipedePoint temp = nextTarget;
         nextTarget = nextTarget.getRandomPath(lastTarget);
         lastTarget = temp;
         rotate(nextTarget.transform);
     }
 }
Example #4
0
 public override void initCentipedeBody()
 {
     if (!fixedHead)
     {
         int randomPosition = Random.Range(0, points.Length);
         transform.position = points[randomPosition].transform.position;
         this.nextTarget    = points[randomPosition];
         this.lastTarget    = nextTarget;
         rotate(nextTarget.transform);
     }
 }
Example #5
0
    public static CentipedePoint getNearestTarget(Transform currentPosition, CentipedePoint[] elements)
    {
        CentipedePoint nearestTarget      = null;
        float          closestDistanceSqr = Mathf.Infinity;

        foreach (CentipedePoint potentialTarget in elements)
        {
            if (!potentialTarget.gameObject.activeInHierarchy)
            {
                break;
            }
            Vector3 directionToTarget = potentialTarget.transform.position - currentPosition.position;
            float   dSqrToTarget      = directionToTarget.sqrMagnitude;
            if (dSqrToTarget < closestDistanceSqr)
            {
                closestDistanceSqr = dSqrToTarget;
                nearestTarget      = potentialTarget;
            }
        }

        return(nearestTarget);
    }