示例#1
0
    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);
        }
    }
示例#2
0
    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++;
    }
示例#3
0
    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);
                }
            }
        }
    }