IEnumerator Compute() { while (true) { x = spline.GetClosestPointAtSpline(transform.position); yield return(new WaitForSeconds(1f)); } }
public void Create(Vector3 pos, float initSpeed, string name, Texture2D pic) { trail.Emit = false; hud.SetHudNameAndPic(name, pic, this); mov = this.gameObject.GetComponent <CatmullRomMovement>(); spline = (CatmullRomSpline)GameObject.Find("Root").GetComponent <CatmullRomSpline>(); mov.startOffset = spline.GetClosestPointAtSpline(pos); mov.speed = initSpeed; mov.DelayedStart(); trail.Emit = true; float hue = Random.Range(0.01f, 0.999f); for (int i = 0; i < 5; i++) { gradientColor[i].color = new HSBColor((hue + (hueStep * i)) % 1f, 1, 1, 1 - (0.25f * i)).ToColor(); gradientColor[i].time = i * 0.25f; gradientAlpha[i].alpha = 1 - (0.25f * i); gradientAlpha[i].time = i * 0.25f; } gradient.SetKeys(gradientColor, gradientAlpha); trail.TrailData.ColorOverLife = gradient; }
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))); } }
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); } } } }