Ejemplo n.º 1
0
		public virtual void Restart() {
			GetComponent<Collider>().enabled = true;
			direccion = direccionInicial;
			transform.position = posicionInicial;
			GetComponent<Rigidbody>().constraints = constraintsIniciales;
			ResetDirection();
			if (!GetComponent<Rigidbody>().isKinematic)
				GetComponent<Rigidbody>().velocity = Vector3.zero;
		}
Ejemplo n.º 2
0
    void Update()
    {
        // Calculamos la distancia horizontal recorrida desde el último rebote
        WalkedDistanceH = Math.Abs(PlatformTransform.position.x - ReferencePingPongHPosition);

        // Calculamos la distancia vertical recorrida desde el último rebote
        WalkedDistanceV = Math.Abs(PlatformTransform.position.y - ReferencePingPongVPosition);

        if (MaxRecorridoPingPong != -1 && WalkedDistanceH >= MaxRecorridoPingPong)
        {
            // Si la función de Ping-Pong esta activada y se ha hecho el máximo recorrido en horizontal, la plataforma cambia de sentido
            if (SentidoH == DireccionH.Izquierda)
            {
                SentidoH = DireccionH.Derecha;
            }
            else
            {
                SentidoH = DireccionH.Izquierda;
            }

            // Actualizamos la posición horizontal de referencia para el cálculo de rebote horizontal (ping-pong)
            ReferencePingPongHPosition = PlatformTransform.position.x;
        }

        if (MaxRecorridoPingPong != -1 && WalkedDistanceV >= MaxRecorridoPingPong)
        {
            // Si la función de Ping-Pong está activada y se ha hecho el máximo recorrido en vertical, la plataforma cambia de sentido
            if (SentidoV == DireccionV.Arriba)
            {
                SentidoV = DireccionV.Abajo;
            }
            else
            {
                SentidoV = DireccionV.Arriba;
            }

            // Actualizamos la posicion vertical de referencia para el calculo de rebote vertical (ping-pong)
            ReferencePingPongVPosition = PlatformTransform.position.y;
        }

        // Configuramos el sentido del movimiento horizontal
        if (SentidoH == DireccionH.Izquierda)
        {
            VelocidadH = -Math.Abs(VelocidadH);
        }
        else
        {
            VelocidadH = Math.Abs(VelocidadH);
        }

        // Configuramos el sentido del movimiento vertical
        if (SentidoV == DireccionV.Abajo)
        {
            VelocidadV = -Math.Abs(VelocidadV);
        }
        else
        {
            VelocidadV = Math.Abs(VelocidadV);
        }

        // Movemos la plataforma
        PlatformTransform.Translate(new Vector3(VelocidadH, VelocidadV, 0) * Time.deltaTime);
    }
Ejemplo n.º 3
0
		void Awake() {
			direccionInicial = direccion;
			posicionInicial = transform.position;
			constraintsIniciales = GetComponent<Rigidbody>().constraints;
			ResetDirection();
		}