public CentipedePoint getRandomPath(CentipedePoint t) { CentipedePoint randomPoint; do { randomPoint = possibleWays[Random.Range(0, possibleWays.Length)]; } while (randomPoint.Equals(t)); return(randomPoint); }
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; }
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); } }
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); } }
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); }