void FixedUpdate() { if (spline.IsReady && isRunning) { if (loopMode == LoopMode.ONCE) { _t += speed; } else if (loopMode == LoopMode.LOOP) { if (_t >= splineTimeLimit) { _t = 0f; } else { _t += speed; } } else if (loopMode == LoopMode.PINGPONG) { if (_t >= splineTimeLimit || _t <= 0f) { speed = -speed; } _t += speed; } if (_t > splineTimeLimit) { _t = splineTimeLimit; if (destroyOnReachingEnd && isWorking) { //Debug.Log("Returning OP, reached end. Limit: " + splineTimeLimit); pool.Return(GetComponent <Opponent>()); isWorking = false; } } if (_t < 0) { _t = 0f; } if (useLerp) { myTransform.position = Vector3.Lerp(myTransform.position, spline.GetPositionAtTime(_t) + offset, Time.deltaTime * 5); } else { myTransform.position = spline.GetPositionAtTime(_t) + offset; } spline.GetRotAtTime(_t, this.gameObject); } }
IEnumerator EventCoroutine(Props p) { Vector3 position = new Vector3(0, 0, 0); int i = 0; while (true) { if (p.stack.Count > 0 && p.isEventInProgress && mov.isPlaying && !mov.isGameOver) { Debug.Log("Spawning: " + p.name); if (!p.worldPos) { position = vehicle.position + p.propRezOffset + new Vector3(Random.Range(-p.randomness.x, p.randomness.x), Random.Range(-p.randomness.y, p.randomness.y), Random.Range(-p.randomness.z, p.randomness.z)); position += new Vector3(0, spline.GetPositionAtTime(spline.GetClosestPointAtSpline(position, 10)).y, 0); //Affect only Y-Axis } else { position = p.propRezOffset + new Vector3(Random.Range(-p.randomness.x, p.randomness.x), Random.Range(-p.randomness.y, p.randomness.y), Random.Range(-p.randomness.z, p.randomness.z)); } p.stack.Pop().GetComponent <PropPoolObject>().Create(position, p.extraData); p.availableObjects = p.stack.Count; i++; } yield return(new WaitForSeconds(Random.Range(p.minSpawnInterval, p.maxSpawnInterval))); } }
public void Generate(float splineStart, float splineEnd) { Debug.Log("Generating side collider from " + splineStart.ToString("f2") + " to " + splineEnd.ToString("f2")); if (childGameObject == null) { childGameObject = new GameObject(); childGameObject.name = "SideCollider"; childGameObject.transform.parent = myTransform; if (childCollider == null) { childCollider = childGameObject.AddComponent <MeshCollider>(); childGameObject.AddComponent <MeshRenderer>(); childGameObject.AddComponent <MeshFilter>(); } } int verticesCounter = 0; float f_iter_increment = (splineEnd - splineStart) / partsNumber; float f_iter = splineStart; Vector3 pos; // Generate vertices while (f_iter < splineEnd) { pos = spline.GetPositionAtTime(f_iter) + offset; vertices[verticesCounter++] = pos; vertices[verticesCounter++] = pos + new Vector3(0, colliderHeight, 0); f_iter += f_iter_increment; } mesh.vertices = vertices; if (!trianglesGenerated) { int trianglesCounter = 0; for (int i = 0; i < (partsNumber * 2 - 2); i += 2) { triangles[trianglesCounter++] = i; triangles[trianglesCounter++] = i + 2; triangles[trianglesCounter++] = i + 1; triangles[trianglesCounter++] = i + 5; triangles[trianglesCounter++] = i + 3; triangles[trianglesCounter++] = i + 4; } mesh.triangles = triangles; trianglesGenerated = true; } childGameObject.GetComponent <MeshFilter>().sharedMesh = null; childGameObject.GetComponent <MeshFilter>().sharedMesh = mesh; childCollider.sharedMesh = null; childCollider.sharedMesh = mesh; }
void AddSegment() { Vector3 centerPos = spline.GetPositionAtTime(zStep * zIterator); Quaternion rot = spline.GetRotAtTime(zStep * zIterator); log("Centerpos: " + centerPos); Vector3 vertexPos; vertexPos = centerPos; Instantiate(markerContainer, vertexPos, rot); zIterator++; }
IEnumerator CreateVertices() { yield return(new WaitForEndOfFrame()); double startTime = Time.realtimeSinceStartup; offset = new Vector3(-x_spacing / 2, offset.y, offset.z); if (previousPart == null && this.gameObject.name != "0") { yield return(StartCoroutine(PreviousPartSearch())); } Vector3 position = Vector3.zero; Vector3 splinePos; int howManyVertexes = 0; lastRow = null; counter = 0; float _step = (to - from) / (rows - 1); lastRow = new List <Vector3>(); for (int j = 0; j < rows; j++) { splinePos = spline.GetPositionAtTime(_step * j + from); for (int i = 0; i < columns; i++) { //Log("Putting "+howManyVertexes+" at vert "+ (j*columns+i).ToString() +", pos x = "+i+", y = "+j); //Vector3 position = new Vector3(i * x_spacing + UnityEngine.Random.Range(-randomness, randomness), profileCurve.Evaluate(i * evaluationStep + UnityEngine.Random.Range(-evaluationDisturbance, evaluationDisturbance)) * y_spacing + UnityEngine.Random.Range(-randomness, randomness)); position = new Vector3(x_spacing * args[i] + UnityEngine.Random.Range(-randomness, randomness), profileCurve.Evaluate(args[i]) * y_spacing + UnityEngine.Random.Range(-evaluationDisturbance, evaluationDisturbance) * y_spacing, 0); position += (splinePos + offset); //preliczac offset na podstawie x_spacing if (j == rows - 1) { lastRow.Add(position); } else if (j == 0) { if (gameObject.name != "0") { /*yield return new WaitForEndOfFrame(); * previousPart = (MeshGenerator) GameObject.Find( (int.Parse(gameObject.name) - 1).ToString() ).GetComponent<MeshGenerator>() as MeshGenerator; * if(previousPart == null) Debug.Log(this.gameObject + " couldn't find previous part! "+(int.Parse(gameObject.name) - 1).ToString()); */ if (previousPart == null) { Debug.Log(this.gameObject.name + ": Warning! previousPart == null"); } while (previousPart.lastRow.Count < columns) { yield return(new WaitForSeconds(0.1f)); } position = previousPart.lastRow[i]; } } howManyVertexes = GetSplitCount(i, j); if (!stacksGenerated) { Vertex v = new Vertex(position); Stack <int> vertexStack = new Stack <int>(); for (int p = 0; p < howManyVertexes; p++) { vertices[counter] = position; vertexStack.Push(counter); counter++; } v.indexes = vertexStack; stacksOfVertexes.Add(v); } else { stacksOfVertexes[j * columns + i].position = position; for (int p = 0; p < howManyVertexes; p++) { vertices[counter] = position; counter++; } } } if (Time.realtimeSinceStartup - startTime > 0.015) { yield return(new WaitForEndOfFrame()); } } stacksGenerated = true; if (!trianglesGenerated) { StartCoroutine(GenerateTriangles()); } else { ChangeVertices(); } }
private MeshGenerator GetCorrespondingPathPart() { //float splineClosestPosition = spline.GetClosestPointAtSpline(myTransform.position); float splineClosestPosition = spline.GetClosestPointAtSpline(vehicle.MyTransform.position) + 5f; caveLength = 100; Debug.Log("Creating cave at spline pos: " + splineClosestPosition + " which is Vector3 world pos = " + spline.GetPositionAtTime(splineClosestPosition)); for (int i = 0; i < meshPool.allObjects.Count; i++) { if (meshPool.allObjects[i].from <= splineClosestPosition && meshPool.allObjects[i].to >= splineClosestPosition) { // Debug.Log("Selected mesh is: "+meshPool.allObjects[i]); return(meshPool.allObjects[i]); } } Debug.LogWarning("Corresponding path of MeshGenerator was not found, probably cave exceeds rendered tunnel length. Closest point: " + splineClosestPosition.ToString("f2")); return(null); }
void FixedUpdate() { if (!isPaused) { if (controlsEnabled) { dir = inputManager.dir; forceAffector = new Vector3(forceAffector.x, 0, forceAffector.z / 100); forceAffector = Vector3.ClampMagnitude(forceAffector, forceAffectorMultiplier * 10); vect = new Vector3(directionSensitivity * dir * -1f, 0, fwdSpeed * (1 + (accel))); vect += forceAffector * (1 - controlMultiplier); if (!isGameOver) { transform.Translate(vect); } myTransform.position = new Vector3(myTransform.position.x, spline.GetPositionAtTime(spline.GetClosestPointAtSpline(myTransform.position, 20)).y + 2, myTransform.position.z); Vector3 nearFuturePos = spline.GetPositionAtTime(spline.GetClosestPointAtSpline(myTransform.position, 20) + 0.1f); float cameraXAngle = myTransform.position.y - nearFuturePos.y; cameraRotationTarget = Quaternion.Euler(cameraXAngle * 4 + highSpeedCameraAffector, dir * 10, dir * cameraRotSensitivityZ); uiRotationTarget = Quaternion.Euler(accel * uiRotSensitivityX, dir * uiRotSensitivityY, dir * uiRotSensitivityZ); cameraTransform.localRotation = Quaternion.Lerp(cameraTransform.localRotation, cameraRotationTarget, Time.deltaTime * rotationSpeed); playerHealthBar.value = playerHealth / 100f; if (playerHealth != playerOldHealth) { playerHealthText.text = "Health: " + playerHealth.ToString("f2") + "%"; } playerOldHealth = playerHealth; if (shouldRotateUI) { foreach (Transform t in uiPanelElements) { t.localRotation = Quaternion.Lerp(t.localRotation, uiRotationTarget, Time.deltaTime * rotationSpeed); } } if (shouldTweenFOV) { cam.fieldOfView = Mathf.Lerp(cam.fieldOfView, 90 + (accel * 75), Time.deltaTime * rotationSpeed); } Vector3 left = transform.TransformDirection(Vector3.left); Vector3 right = transform.TransformDirection(Vector3.right); RaycastHit hit; if (Physics.Raycast(transform.position, left, out hit, minChargeDistance)) { nearMissCharge += 0.1f; leftGradient.alpha += 0.1f; if (hit.collider.gameObject.tag == "Obstacle" && !nearMissCooldown) { score += 200; ScoreBonusManager.Instance.AddScore(200, "Near Miss"); StartCoroutine("NearMissCooldown"); } } if (Physics.Raycast(transform.position, right, out hit, minChargeDistance)) { nearMissCharge += 0.1f; rightGradient.alpha += 0.1f; if (hit.collider.gameObject.tag == "Obstacle" && !nearMissCooldown) { score += 200; ScoreBonusManager.Instance.AddScore(200, "Near Miss"); StartCoroutine("NearMissCooldown"); } } if (nearMissCharge >= nearMissChargeCap) { nearMissCharge = nearMissChargeCap; } chargeLineRight.fillAmount = nearMissCharge / nearMissChargeCap; chargePercentageLabel.text = ((nearMissCharge / nearMissChargeCap) * 100).ToString("f1") + "%"; if (nearMissCharge < 1f) { TriggerSlowDown(); } } else { if (spline.IsReady) { if (loopMode == LoopMode.ONCE) { _t += menuFwdSpeed; } else if (loopMode == LoopMode.LOOP) { if (_t >= splineTimeLimit) { _t = 0f; } else { _t += menuFwdSpeed; } } else if (loopMode == LoopMode.PINGPONG) { if (_t >= splineTimeLimit || _t <= 0f) { menuFwdSpeed = -menuFwdSpeed; } _t += menuFwdSpeed; } if (_t > splineTimeLimit) { _t = splineTimeLimit; } if (_t < 0) { _t = 0f; } myTransform.position = Vector3.Lerp(myTransform.position, spline.GetPositionAtTime(_t), Time.deltaTime * 5); //myTransform.position = spline.GetPositionAtTime(_t); spline.GetRotAtTime(_t + 0.5f, this.gameObject); } } } }