void CreateAutoPathEnhanced() { path = FindObjectOfType(typeof(CarAutoPath)) as CarAutoPath; int pathIndex = 0; foreach (var p in path.pathNodes) { GameObject go = new GameObject("Node" + pathIndex); Vector3 currentSpot = p.position; RaycastHit hit; Physics.Raycast(currentSpot + Vector3.up * 5, -Vector3.up, out hit, 100f, (1 << LayerMask.NameToLayer("Roads"))); go.transform.position = new Vector3(currentSpot.x, hit.point.y + 0.2f, currentSpot.z); if (pathIndex < path.pathNodes.Count - 1) { go.transform.LookAt(path.pathNodes[pathIndex + 1].position); //this is in order to orient the pathNodes to the road direction } else { go.transform.LookAt(path.pathNodes[0].position); //the last node takes the orientation of the first since it doesn't have a node in front of it } go.transform.SetParent(gameObject.transform); go.AddComponent <SphereCollider>(); //go.GetComponent<SphereCollider>().isTrigger = true; go.layer = LayerMask.NameToLayer("Graphics"); go.tag = "Waypoint"; pathIndex++; } }
void Start() { path = GameObject.Find("AutoPath").GetComponent <CarAutoPath>(); //Points = new Vector3[path.pathNodes.Count]; //int i = 0; //foreach (var p in path.pathNodes) //{ // Vector3 currentSpot = p.position;// HermiteMath.HermiteVal(prevWaypoint, currentWaypoint, prevTangent, currentTangent, currentPc); // RaycastHit hit; // Physics.Raycast(currentSpot + Vector3.up * 5, -Vector3.up, out hit, 100f, ~(1 << LayerMask.NameToLayer("Traffic"))); // Vector3 hTarget = new Vector3(currentSpot.x, hit.point.y + 0.2f, currentSpot.z); // Points[i] = hTarget; // ++i; //} linerenderer = gameObject.GetComponent <LineRenderer>(); linerenderer.alignment = LineAlignment.Local; //linerenderer.positionCount = Points.Length; //Gradient gradient = new Gradient(); //gradient.SetKeys( // new GradientColorKey[] { new GradientColorKey(Color.green, 1.0f), new GradientColorKey(Color.green, 1.0f) }, // new GradientAlphaKey[] { new GradientAlphaKey(1.0f, 1.0f), new GradientAlphaKey(1.0f, 1.0f) } // ); //linerenderer.colorGradient = gradient; int ii = 0; //foreach (var p in Points) //{ // linerenderer.SetPosition(ii, p); // ++ii; //} }