Esempio n. 1
0
    void Start()
    {
        int randomValue = 0;

        do
        {
            randomValue = Random.Range(-1, 1);
        } while (randomValue == 0);
        Debug.Log(randomValue);
        distance     *= randomValue;
        interpolation = new FloatInterpolation(transform.position.y, GetTargetY());
        interpolation.SwitchLerp(FloatInterpolation.LerpMode.Smoothstep);
        //interpolation.LerpTime = 2;
    }
    protected IEnumerator HorizontalMove(float targetPositionX, float time)
    {
        //este movimiento al no ser  hecho con  collision= characterController.Move (velocity) puede generar probllemas de colisiones
        //float currentVelocity=0;
        //transform.position = new Vector3( Mathf.SmoothDamp (transform.position.x, targetPositionX, ref currentVelocity,.01f),transform.position.y,transform.position.z);
        FloatInterpolation targetInterpolation = new FloatInterpolation(transform.position.x, targetPositionX); // esta es una de mis herramientas para realizar interpolaciones de valores.

        targetInterpolation.LerpTime = .1f;                                                                     //este valor debería cambiar con la velocidad del vehiculo... a mayor velocidad menor tiempo se debe demorar en moverse horizontalmente.
        targetInterpolation.SwitchLerp(FloatInterpolation.LerpMode.Smootherstep);
        OnRutine = true;
        while (transform.position.x != targetInterpolation.EndPos)
        {
            targetInterpolation.UpdateLerp();
            float newPositionX = targetInterpolation.InterpolatedValue;
            transform.position = new Vector3(newPositionX, transform.position.y, transform.position.z);
            yield return(null);
        }

        OnRutine = false;
    }