예제 #1
0
    void OnCollisionExit(Collision collision)
    {
        //Only move players
        if (collision.gameObject.tag != Constants.COLLIDE_WITH_MOVING_PLATFORM_STRING)
        {
            return;
        }

        //Null check for the movement ability
        BaseMovementAbility movement = (BaseMovementAbility)collision.transform.parent.gameObject.GetComponent <BaseMovementAbility> ();

        if (movement == null)
        {
            return;
        }

        //Check if the player should be added or changed
        for (int i = 0; i < m_PlayersToMove.Count; i++)
        {
            if (movement == m_PlayersToMove[i].movement)
            {
                //Check if the player should be removed from the array or flaged to be removed next frame
                if (m_PlayersToMove[i].foundLastFrame == true)
                {
                    m_PlayersToMove[i] = new PlayersToMove(m_PlayersToMove[i].movement, m_PlayersToMove[i].normal, false);
                }
                else
                {
                    //Debug.Log(m_PlayersToMove[i].movement.gameObject.name+ "   removed");
                    //m_PlayersToMove.RemoveAt(i);
                }
            }
        }
    }
예제 #2
0
    //When the player collides with this platform
    void OnCollisionStay(Collision collision)
    {
        //Only move players
        if (collision.gameObject.tag != Constants.COLLIDE_WITH_MOVING_PLATFORM_STRING)
        {
            return;
        }

        //Null check for the movement ability
        BaseMovementAbility movement = (BaseMovementAbility)collision.transform.parent.gameObject.GetComponent <BaseMovementAbility> ();

        if (movement == null)
        {
            return;
        }

        //Get the average direction that the player has collided with the moving platform
        ContactPoint[] contacts      = collision.contacts;
        Vector3        averageNormal = Vector3.zero;

        foreach (ContactPoint contactPoint in contacts)
        {
            averageNormal += contactPoint.normal;
            Debug.DrawRay(contactPoint.point, contactPoint.normal, Color.white);
        }
        averageNormal /= -contacts.Length;

        //Check if the player should be added or changed
        bool found = false;

        for (int i = 0; i < m_PlayersToMove.Count; i++)
        {
            if (movement == m_PlayersToMove[i].movement)
            {
                m_PlayersToMove[i] = new PlayersToMove(movement, averageNormal, true);
                found = true;
            }
        }
        if (found == false)
        {
            m_PlayersToMove.Add(new PlayersToMove(movement, averageNormal, true));
            Debug.Log(m_PlayersToMove[m_PlayersToMove.Count - 1].movement.gameObject.name + "   added");
        }
    }
    //When the player collides with this platform
    void OnCollisionStay(Collision collision)
    {
        //Only move players
        if (collision.gameObject.tag != Constants.COLLIDE_WITH_MOVING_PLATFORM_STRING)
        {
            return;
        }

        //Null check for the movement ability
        BaseMovementAbility movement = (BaseMovementAbility)collision.transform.parent.gameObject.GetComponent<BaseMovementAbility> ();
        if (movement == null)
        {
            return;
        }

        //Get the average direction that the player has collided with the moving platform
        ContactPoint[] contacts = collision.contacts;
        Vector3 averageNormal = Vector3.zero;
        foreach (ContactPoint contactPoint in contacts)
        {
            averageNormal += contactPoint.normal;
            Debug.DrawRay(contactPoint.point, contactPoint.normal, Color.white);
        }
        averageNormal /= -contacts.Length;

        //Check if the player should be added or changed
        bool found = false;
        for (int i =0; i < m_PlayersToMove.Count; i++)
        {
            if (movement == m_PlayersToMove[i].movement)
            {
                m_PlayersToMove[i] = new PlayersToMove(movement, averageNormal, true);
                found = true;
            }
        }
        if (found == false)
        {
            m_PlayersToMove.Add(new PlayersToMove(movement, averageNormal, true));
            Debug.Log(m_PlayersToMove[m_PlayersToMove.Count-1].movement.gameObject.name+ "   added");
        }
    }
    void OnCollisionExit(Collision collision)
    {
        //Only move players
        if (collision.gameObject.tag != Constants.COLLIDE_WITH_MOVING_PLATFORM_STRING)
        {
            return;
        }

        //Null check for the movement ability
        BaseMovementAbility movement = (BaseMovementAbility)collision.transform.parent.gameObject.GetComponent<BaseMovementAbility> ();
        if (movement == null)
        {
            return;
        }

        //Check if the player should be added or changed
        for (int i =0; i < m_PlayersToMove.Count; i++)
        {
            if (movement == m_PlayersToMove[i].movement)
            {
                //Check if the player should be removed from the array or flaged to be removed next frame
                if (m_PlayersToMove[i].foundLastFrame == true)
                {
                    m_PlayersToMove[i] = new PlayersToMove(m_PlayersToMove[i].movement, m_PlayersToMove[i].normal, false);
                }
                else
                {
                    //Debug.Log(m_PlayersToMove[i].movement.gameObject.name+ "   removed");
                    //m_PlayersToMove.RemoveAt(i);
                }
            }
        }
    }