public void PlaceObjByGraph(GameObject obj) { //Debug.Log(obj.name); place = ScriptableObject.CreateInstance <PlaceObjectToGround>(); rotCalc = ScriptableObject.CreateInstance <RotationCalculator>(); rotCalc.rectRad = 1.0f; rotCalc.rectRadZ = 1.0f; rotCalc.yMod = 2.0f; rotCalc.maxAngleX = 60.0f; rotCalc.maxAngleZ = 45.0f; //Debug.Log("graph length: "+graphLength); GameObject tempObj; float rnd = 0.2f; for (int i = 0; i < vec3points.Length - 1; i++) { if (i % rar == 0) { tempObj = Instantiate(obj, objsParent); tempObj.transform.position = new Vector3(vec3points[i].x, vec3points[i].y + offset, vec3points[i].z); tempObj.transform.parent = objsParent; rnd = 0.2f; tempObj.transform.rotation = new Quaternion( tempObj.transform.rotation.x, tempObj.transform.rotation.y + Random.Range(-rnd, rnd), tempObj.transform.rotation.z, tempObj.transform.rotation.w ); tempObj.transform.rotation = Vec3Mathf.GetDir(vec3points[i], vec3points[0]); rotCalc.MakeCalculations(tempObj.transform, tempObj.transform); place.corr = corr; place.Place(ref tempObj); } } tempObj = Instantiate(obj, objsParent); tempObj.transform.position = new Vector3(vec3points[vec3points.Length - 1].x, vec3points[vec3points.Length - 1].y + offset, vec3points[vec3points.Length - 1].z); tempObj.transform.parent = objsParent; tempObj.transform.rotation = new Quaternion( tempObj.transform.rotation.x, tempObj.transform.rotation.y + Random.Range(-rnd, rnd), tempObj.transform.rotation.z, tempObj.transform.rotation.w ); //tempObj.transform.rotation = Vec3Mathf.GetDir(vec3points[vec3points.Length - 3], vec3points[vec3points.Length-2]); rotCalc.MakeCalculations(tempObj.transform, tempObj.transform); place.corr = corr; place.Place(ref tempObj); }
IEnumerator ModifyAngle() { while (true) { rotCalc.rectRad = rectRad; rotCalc.rectRadZ = rectRadZ; rotCalc.yMod = yMod; rotCalc.MakeCalculations(transform, modelToRotate); rotCalc.MakeCalculationsZ(transform, modelToRotate); if (debugMode) { rotCalc.DebugLines(); } yield return(new WaitForSeconds(0.01f)); } }
void Update() { timeBetSteps = freq / agent.velocity.magnitude; if (stepIndex == poolSize) { stepIndex = 0; } if (agent.velocity.magnitude > 0) { stepTimer += Time.deltaTime; if (stepTimer > timeBetSteps) { stepTimer = 0; Ray ray = new Ray(stepPos.position, -Vector3.up); RaycastHit hit; if (Physics.Raycast(ray, out hit, 2f, groundMask)) { steps [stepIndex].position = hit.point + Vector3.up * 2.0f; steps[stepIndex].rotation = Vec3Mathf.GetDir(transform.position, steps[stepIndex].position); float corr = Random.Range(-0.3f, 0.3f); steps[stepIndex].position = new Vector3( steps[stepIndex].position.x + corr, steps[stepIndex].position.y, steps[stepIndex].position.z ); rotCalc.MakeCalculations(steps[stepIndex], steps[stepIndex]); rotCalc.MakeCalculationsZ(steps[stepIndex], steps[stepIndex]); place.Place(steps[stepIndex]); steps [stepIndex].gameObject.SetActive(true); stepIndex++; } } } }