/*******************************/ protected override void Awake() { base.Awake(); shareCorner = this; _ballPath = new List <Vector3>(); _cornerShootDirection = cornerDirection.Both; }
public void cornerShoot(cornerDirection cornerShootDirection, float curveLevel, float difficulty) { // Debug.Log("AI shoot"); EventShoot(); _isCornerShoot = true; _ballPath.Clear(); _ballPath = createPath(cornerShootDirection, curveLevel, difficulty, _cachedTrans.position); _index = _ballPath.Count - 1; // di nguoc tu cuoi' mang~ ve dau` mang~ /*************** Debug ****************/ _multiSelection.count = _ballPath.Count; for (int i = 0; i < _multiSelection._gos.Count; ++i) { Destroy(_multiSelection._gos[i]); } _multiSelection._gos.Clear(); for (int i = 0; i < _ballPath.Count; ++i) { GameObject go = new GameObject(); go.transform.position = _ballPath[i]; _multiSelection._gos.Add(go); } /*******************************/ }
public List <Vector3> createPath(cornerDirection direction, float curveLevel, float difficulty, Vector3 ballPostion) { float ballDistance = new Vector2(Mathf.Abs(ballPostion.x), Mathf.Abs(ballPostion.z)).magnitude; int slide = 10; List <Vector3> listTemp = new List <Vector3>(); Vector3 pointEnd, pointMiddle = Vector3.zero; // diem dich' den' //henry add: // pointEnd.z = -3f; //Dat lui dich den ve phia truoc cau mon // pointEnd.z = -3f; //Dat lui dich den ve phia truoc cau mon Vector3 pointStart = ballPostion; // diem bat dau if (direction == cornerDirection.Both) { direction = (cornerDirection)Random.Range(0, 2); } // *********************** Tinh yMid va yEnd ************************ //float yEndMin = 3f; //float yEndMax = 3.5f; //float xEndMin = 0f; //float xEndMax = 0.1f; //float xEnd, yEnd; xEndC = Random.Range(xEndC - 0.2f, xEndC + 0.2f); yEndC = Random.Range(yEndC - 0.2f, yEndC + 0.2f); // random ra y end //Gan diem cuoi cho dich den cua bong khi sut phat goc pointEnd = new Vector3(xEndC, yEndC, zEndC); // diem dau tien duoc add vo List cung la diem cuoi' cung se duoc lay ra // ********************** Tim x la do be~ cong ************************* _maxLeft = -15f; // -3.5f _maxRight = 15f; //3.5f float curveFactor = Mathf.Lerp(0f, 0.95f, curveLevel); // do kho cua xoay' float a = Random.Range(_maxLeft, _maxLeft * curveFactor); // random xoay ben fai float b = Random.Range(_maxRight * curveFactor, _maxRight); // random xoay ben trai float zCurve = (((int)Random.Range(0, 2)) == 0) ? a : b; // random chon xoay ben fai hay ben trai // float xCurve = Mathf.Lerp(_maxLeft, _maxRight, curveLevel); // do be cong duong di cua banh EventChangeCurveRange(zCurve); float z = Math.Abs((pointEnd.z + pointStart.z) / 2f); z += zCurve; // lam cho x cua diem giua~ bi lech se duoc ket qua la lam cho duong banh bi be cong xoay' // *********************************************** listTemp.Clear(); pointMiddle.x = (pointEnd.x + pointStart.x) / 2f; pointMiddle.y = pointEnd.y * 2.5f; //(pointEnd.y + pointStart.y) / 2f; pointMiddle.z = zEndC; //Gia tri nay quyet dinh huong bong tat tuong duong vi tri cua endpoint//pointEnd.z*2;//(pointEnd.z + pointStart.z) / 2f; listTemp.Clear(); listTemp.Add(pointEnd); listTemp.Add(pointMiddle); listTemp.Add(pointStart); // ******************* tim diem cach khung thanh mot khoang cach mindistance ********************* Vector3 closestPointToGoal = findPointInPathAtZ(Interpolate.Ease(easeType), listTemp.ToArray(), slide, -3f); // **************************************** // ******************** Final path ******************** List <Vector3> retVal = new List <Vector3>(); IEnumerator <Vector3> nodes = Interpolate.NewBezier(Interpolate.Ease(easeType), listTemp.ToArray(), slide).GetEnumerator(); // tao ra path gom cac diem _debugPath.Clear(); while (nodes.MoveNext()) // lay cac diem cua path ra { _debugPath.Add(nodes.Current); //if(nodes.Current.z < -3f) if (nodes.Current.z < -_ballControlLimit) { retVal.Add(nodes.Current); } } retVal.Insert(0, closestPointToGoal); retVal.RemoveAt(retVal.Count - 1); return(retVal); }