void MakeScriptedPath() { TrackScript script = new TrackScript(); if (script.Read(pathToLoad)) { path = new CarPath(); TrackParams tparams = new TrackParams(); tparams.numToSet = 0; tparams.rotCur = Quaternion.identity; tparams.lastPos = startPos.position; float dY = 0.0f; float turn = 0f; Vector3 s = startPos.position; s.y = 0.5f; span.x = 0f; span.y = 0f; span.z = spanDist; float turnVal = 10.0f; foreach (TrackScriptElem se in script.track) { if (se.state == TrackParams.State.AngleDY) { turnVal = se.value; } else if (se.state == TrackParams.State.CurveY) { turn = 0.0f; dY = se.value * turnVal; } else { dY = 0.0f; turn = 0.0f; } for (int i = 0; i < se.numToSet; i++) { Vector3 np = s; PathNode p = new PathNode(); p.pos = np; path.nodes.Add(p); turn = dY; Quaternion rot = Quaternion.Euler(0.0f, turn, 0f); span = rot * span.normalized; span *= spanDist; s = s + span; } } } }
void MakeScriptedPath() { TrackScript script = new TrackScript(); if (script.Read(pathToLoad)) { carPath = new CarPath(); TrackParams tparams = new TrackParams(); tparams.numToSet = 0; tparams.rotCur = Quaternion.identity; tparams.lastPos = startPos.position; float dY = 0.0f; float turn = 0f; Vector3 s = startPos.position; s.y = 0.5f; span.x = 0f; span.y = 0f; span.z = spanDist; float turnVal = 10.0f; List <Vector3> points = new List <Vector3>(); foreach (TrackScriptElem se in script.track) { if (se.state == TrackParams.State.AngleDY) { turnVal = se.value; } else if (se.state == TrackParams.State.CurveY) { turn = 0.0f; dY = se.value * turnVal; } else { dY = 0.0f; turn = 0.0f; } for (int i = 0; i < se.numToSet; i++) { Vector3 np = s; PathNode p = new PathNode(); p.pos = np; points.Add(np); turn = dY; Quaternion rot = Quaternion.Euler(0.0f, turn, 0f); span = rot * span.normalized; span *= spanDist; s = s + span; } } for (int i = 0; i < points.Count; i++) { Vector3 point = points[(int)nfmod(i, (points.Count))]; Vector3 previous_point = points[(int)nfmod(i - 1, (points.Count))]; Vector3 next_point = points[(int)nfmod(i + 1, (points.Count))]; PathNode p = new PathNode(); p.pos = point; p.rotation = Quaternion.LookRotation(next_point - previous_point, Vector3.up);; carPath.nodes.Add(p); carPath.centerNodes.Add(p); } } }
/* * void MakePointPath() * { * string filename = "thunder_path"; * * TextAsset bindata = Resources.Load(filename) as TextAsset; * * if(bindata == null) * return; * * string[] lines = bindata.text.Split('\n'); * * Debug.Log(string.Format("found {0} path points. to load", lines.Length)); * * path = new CarPath(); * * Vector3 np = Vector3.zero; * * float offsetY = -0.1f; * * foreach(string line in lines) * { * string[] tokens = line.Split(','); * * if (tokens.Length != 3) * continue; * np.x = float.Parse(tokens[0]); * np.y = float.Parse(tokens[1]) + offsetY; * np.z = float.Parse(tokens[2]); * PathNode p = new PathNode(); * p.pos = np; * path.nodes.Add(p); * } * * } */ void MakeScriptedPath() { TrackScript script = new TrackScript(); if (script.Read(GlobalState.script_path)) { path = new CarPath(); TrackParams tparams = new TrackParams(); tparams.numToSet = 0; tparams.rotCur = Quaternion.identity; tparams.lastPos = startPos.position; float dY = 0.0f; //float turn = 0f; Vector3 s = startPos.position; s.y = 0.5f; span.x = 0f; span.y = 0f; span.z = spanDist; float turnVal = 10.0f; float totalTurn = 0.0f; // record the direction foreach (TrackScriptElem se in script.track) { Debug.Log(se.state.ToString()); string thing = ""; // "" means just road, others can be things in the road float thing_offset = 0.0f; float thing_rot = 0.0f; if (se.state == TrackParams.State.AngleDY) { turnVal = se.value; // set how many degrees every node turn } else if (se.state == TrackParams.State.CurveY) { //turn = 0.0f; dY = se.value * turnVal; } else if (se.state == TrackParams.State.CONE) { thing = "cone"; thing_offset = se.value; thing_rot = se.value2; /* * GameObject coneO=Instantiate(cone, s, Quaternion.identity) as GameObject; * coneO.AddComponent<Rigidbody>(); * coneO.AddComponent<BoxCollider>(); * coneO.tag = "pathNode"; */ } else if (se.state == TrackParams.State.BLOCK) { thing = "block"; thing_offset = se.value; thing_rot = se.value2; /* * GameObject blockO=Instantiate(block, s, Quaternion.identity) as GameObject; * blockO.AddComponent<Rigidbody>(); * blockO.AddComponent<BoxCollider>(); * blockO.tag = "pathNode"; */ } else { dY = 0.0f; //turn = 0.0f; } for (int i = 0; i < se.numToSet; i++) { totalTurn += dY; Vector3 np = s; PathNode p = new PathNode(); p.pos = np; p.thing = thing; p.thing_offset = thing_offset; p.thing_rot = Quaternion.Euler(0.0f, thing_rot + totalTurn, 0f); path.nodes.Add(p); //turn = dY; Quaternion rot = Quaternion.Euler(0.0f, dY, 0f); // y turn span = rot * span.normalized; span *= spanDist; s = s + span; } } } }