Esempio n. 1
0
    void Levitation()
    {
        interpolation.UpdateLerp();
        transform.position = new Vector3(transform.position.x, interpolation.InterpolatedValue, transform.position.z);

        if (transform.position.y == interpolation.EndPos)
        {
            distance     *= -1;
            interpolation = new FloatInterpolation(transform.position.y, GetTargetY());
        }
    }
    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;
    }