public static Vector2 getNearSlingShotPos(DotTurn turn, Vector2 fromPos, Vector2 nodePos, float agentSize) { Vector2 dir = nodePos - fromPos; float distFromNode = dir.magnitude; float angleFromNegNodeDir = Mathf.Acos(agentSize / distFromNode) * 180.0f / Mathf.PI; if (turn == DotTurn.TurnRight)// turn right { return((Vector2)(Quaternion.AngleAxis(angleFromNegNodeDir, Vector3.forward) * -dir).normalized * agentSize + nodePos); } else// turn left { return((Vector2)(Quaternion.AngleAxis(-angleFromNegNodeDir, Vector3.forward) * -dir).normalized * agentSize + nodePos); } }
private void OnDrawGizmos() { if (testPath.Count <= 2) { return; } Vector2 thisPos = transform.position; Vector2 prevPos = thisPos; Vector2 segPoint0 = prevPos; Vector2 segPoint1 = testPath[0].position; Vector2 segPoint2 = testPath[1].position; //Vector2[] verts = getSlerpVerts(segPoint0, segPoint1, segPoint2, agentSize, 3); // Original Debug.DrawLine(segPoint0, segPoint1, Color.gray); DotTurn turn = turnLeft_or_Right(segPoint0, segPoint1, segPoint2); if (turn == DotTurn.TurnRight) { Debug.DrawLine(segPoint1, segPoint2, Color.cyan); } else { Debug.DrawLine(segPoint1, segPoint2, Color.red); } // Verts //Debug.DrawLine(segPoint1, verts[0], Color.magenta); //Debug.DrawLine(segPoint1, verts[1], Color.cyan); //Debug.DrawLine(segPoint1, verts[2], Color.magenta); // Slerp //Debug.DrawLine(segPoint0, verts[0], Color.red); //Debug.DrawLine(verts[0], verts[1], Color.red); //Debug.DrawLine(verts[1], verts[2], Color.red); //prevPos = verts[2]; //for (int i=0;i<testPath.Count - 2; i++) //{ // segPoint0 = testPath[i].position; // segPoint1 = testPath[i+1].position; // segPoint2 = testPath[i+2].position; // verts = getSlerpVerts(segPoint0, segPoint1, segPoint2, agentSize, 3); // // Original // Debug.DrawLine(segPoint0, segPoint1, Color.gray); // Debug.DrawLine(segPoint1, segPoint2, Color.gray); // // Verts // for (int j = 0; j < 3; j++) // { // Debug.DrawLine(segPoint1, verts[j], Color.magenta); // } // prevPos = verts[verts.Length - 1]; //} }