protected override void FSMUpdate() { elapsedTime += Time.deltaTime; CurrentState.Reason(playerTransform, transform); CurrentState.Act(playerTransform, transform); StateText.text = "AI STATE IS: " + GetStateString(); if (debugDraw) { UsefullFunctions.DebugRay(transform.position, transform.forward * 5.0f, Color.red); } }
// Update is called once per frame void Update() { direction = (Vector2)(Camera.main.ScreenToWorldPoint(Input.mousePosition) - transform.position); if (Input.GetButton("Move")) { float moveDist = Time.deltaTime * GameHandler.instance.getCharacterSpeed(); if (direction.magnitude > GameHandler.instance.cursorReach) { direction.Normalize(); } else { direction = new Vector2(0, 0); } transform.position += UsefullFunctions.mkVector3(moveDist * direction, 0); } }
private Vector2[] FindSuitableArea() { Vector2[] intersectionPoints = new Vector2[6]; UsefullFunctions.FindCircleIntersections(x_t[0], y_t[0], radiuses[0], x_t[1], y_t[1], radiuses[1], out intersectionPoints[0], out intersectionPoints[1]); UsefullFunctions.FindCircleIntersections(x_t[1], y_t[1], radiuses[1], x_t[2], y_t[2], radiuses[2], out intersectionPoints[2], out intersectionPoints[3]); UsefullFunctions.FindCircleIntersections(x_t[2], y_t[2], radiuses[2], x_t[0], y_t[0], radiuses[0], out intersectionPoints[4], out intersectionPoints[5]); for (int i = 0; i < intersectionPoints.Length; i++) { if (float.IsNaN(intersectionPoints[i].x) || float.IsNaN(intersectionPoints[i].y)) { throw new Exception("Not all intersection points were calculated"); } } Vector2[] result = new Vector2[3]; float minPer; minPer = UsefullFunctions.findDistanceBetweenPoints(intersectionPoints[0], intersectionPoints[1]) + UsefullFunctions.findDistanceBetweenPoints(intersectionPoints[1], intersectionPoints[2]) + UsefullFunctions.findDistanceBetweenPoints(intersectionPoints[2], intersectionPoints[0]); result = new Vector2[] { intersectionPoints[0], intersectionPoints[1], intersectionPoints[2] }; for (int i = 0; i < 3; i++) { for (int j = i + 1; j < 4; j++) { for (int k = j + 1; k < 5; k++) { float z = UsefullFunctions.findDistanceBetweenPoints(intersectionPoints[i], intersectionPoints[j]) + UsefullFunctions.findDistanceBetweenPoints(intersectionPoints[j], intersectionPoints[k]) + UsefullFunctions.findDistanceBetweenPoints(intersectionPoints[k], intersectionPoints[i]); if (z < minPer) { minPer = z; result = new Vector2[] { intersectionPoints[i], intersectionPoints[j], intersectionPoints[k] }; } } } } return(result); }