Beispiel #1
0
    RoomEx SetRoomForPlayer()
    {
        if (m_RoomExs.Length > 0 && m_Player != null)
        {
            RaycastHit hit           = new RaycastHit();
            Transform  roomtransform = null;
            Transform  Lara          = m_Player.transform;

#if (UNITY_5_3_OR_NEWER || UNITY_5_3)
            int mask = Physics.DefaultRaycastLayers & ~(MaskedLayer.Switch | MaskedLayer.Player);
#else
            int mask = Physics.kDefaultRaycastLayers & ~(MaskedLayer.Switch | MaskedLayer.Player);
#endif
            if (Physics.Raycast(Lara.position + Vector3.up * 50, -Vector3.up, out hit, 14096, mask))
            {
                roomtransform = hit.transform; Debug.Log("SetRoomForPlayer");
            }
            else
            {
                Debug.Log("failed SetRoomForPlayer!");
            }

            for (int r = 0; r < m_RoomExs.Length; r++)
            {
                if (m_RoomExs[r].m_Transform == roomtransform)
                {
                    m_CurrentActiveRoom = m_RoomExs[r];
                    break;
                }
            }
        }

        return(m_CurrentActiveRoom);
    }
Beispiel #2
0
    //This is commissioned event fired independently directly on Update
    void PositionChanged(Vector3 position)
    {
        //TODO: Detect Room Change with Raycasting Room
        //FIXED:Heighten raycast origin to handle floor collision through raycast. m_Transform.position + Vector3.up
        //TODO: following Raycast can be done by SeekGround()
        RaycastHit hit = new RaycastHit();

#if (UNITY_5_3_OR_NEWER || UNITY_5_3)
        int mask = Physics.DefaultRaycastLayers & ~(MaskedLayer.Switch | MaskedLayer.Player);
#else
        int mask = Physics.kDefaultRaycastLayers & ~(MaskedLayer.Switch | MaskedLayer.Player);
#endif
        if (Physics.Raycast(m_Transform.position + Vector3.up * 10 * Settings.SceneScaling, -Vector3.up, out hit, m_maxDownRayLength, mask))
        {
            //room changed?
            if (hit.transform != null)
            {
                //there may be lara's current room == null,  first check for this
                if (m_Room != null)
                {
                    if (hit.transform != m_Room.transform)
                    {
                        RoomEx room = hit.transform.GetComponent <RoomEx>();
                        if (room != null) //All hit objects need not to be a room
                        {
                            m_Room = room;
                            if (m_Room != null)
                            {
                                // Debug.Log("m_Room" + m_Room.name + "room flag " + m_Room.Flags);
                            }
                        }
                    }
                }
                else
                {
                    RoomEx room = hit.transform.GetComponent <RoomEx>();
                    if (room != null) //All hit objects need not to be a room
                    {
                        m_Room = room;
                        //Debug.Log("m_Room" + m_Room.name);
                    }
                }
            }
        }

        //may hit ground / may hit water
        if (m_Room != null)
        {
            SetSwimState(m_Room);
        }

        FreeFallHandler();  //free falling will continue until hit ground height
    }
Beispiel #3
0
    RoomEx SetRoomForPlayer()
    {
        if(m_RoomExs.Length > 0 && m_Player!=null )
        {
            RaycastHit hit = new RaycastHit();
            Transform roomtransform = null;
            Transform Lara = m_Player.transform;

            int mask = Physics.kDefaultRaycastLayers & ~(MaskedLayer.Switch | MaskedLayer.Player);
            if(Physics.Raycast(Lara.position + Vector3.up * 50, -Vector3.up, out hit,14096,mask ))
            {
                roomtransform = hit.transform; Debug.Log("SetRoomForPlayer");
            }
            else
            {
                Debug.Log("failed SetRoomForPlayer!");
            }

            for(int r = 0; r < m_RoomExs.Length; r++)
            {
                if(m_RoomExs[r].m_Transform == roomtransform)
                {
                    m_CurrentActiveRoom = m_RoomExs[r];
                    break;
                }
            }
        }

        return m_CurrentActiveRoom;
    }
Beispiel #4
0
    /*function OnCollisionEnter(collision : Collision) {
     *          // Debug-draw all contact points and normals
     *          for (var contact : ContactPoint in collision.contacts)
     *                  Debug.DrawRay(contact.point, contact.normal, Color.white);
     *
     *          // Play a sound if the coliding objects had a big impact.
     *          if (collision.relativeVelocity.magnitude > 2)
     *                  audio.Play();
     *  }
     *
     *
     *  function OnTriggerEnter (other : Collider) {
     *          Destroy(other.gameObject);
     *  }*/


    public void SetSwimState(RoomEx room)
    {
        //return;
        if (IsAvoidingFall() && /*bugfix: except jump*/ (m_bJumping == false)) //dont pull into swimming state when trying to getout of water
        {
            if (m_SwimState == SwimmingState.InWaterSurface)
            {
                //Debug.Log("Getting outof water");
            }
            return;
        }

        if (room == null)
        {
            return;
        }

        if (room != null)
        {
            float surface = room.GetCenterPoint().y;
            if (surface < m_WaterLevel)
            {
                m_WaterLevel = surface;
                SetSwimStateNone();
                Debug.Log("Water Level Changed");
                return;
            }
        }

        if (room != null && (m_bFreeFall || m_bJumping) && (m_SwimState == SwimmingState.None || m_SwimState == SwimmingState.Diving))          //set initial swim state (works only when current room type is Land, not water
        {
            RoomEx.RoomType type = room.GetRoomType();
            m_WaterLevel = room.GetCenterPoint().y;
            //Debug.Log("Room Type:" + type);
            Vector3 heappos = GetHipPosition();

            Bounds room_bound      = room.GetBound();
            float  min_fall_height = room_bound.min.y + room_bound.size.y * 0.1f;

            if ((m_Transform.position.y < (m_WaterLevel - m_Height * 0.3f)) && (type == RoomEx.RoomType.DeepWater))              //enter swimming state machine
            {
                if (m_AnimStatePlayer != null)
                {
                    m_AnimStatePlayer.PlayDiveSFX();
                }
                SetSwimStateDeepWater();
                StopImmediate(null);
            }
            else if ((m_Transform.position.y < min_fall_height) && (type == RoomEx.RoomType.ShalloWater))
            {
                if (heappos.y < m_WaterLevel) //hip is inside water
                {
                    if (m_AnimStatePlayer != null)
                    {
                        m_AnimStatePlayer.PlayDiveSFX();
                    }

                    SetSwimStateShallowWater();
                    StopImmediate(null);
                }
                else
                {
                }
            }
        }



        if (room != null && ((room.Flags & 1) == 1))
        {
            /*if(m_SwimState != SwimmingState.InShallowWater)
             *          {
             *              SetSwimStateShallowWater();
             *          }*/

            float surface = room.GetCenterPoint().y;

            //if ((surface - transform.position.y) > 0.1f && (m_SwimState == SwimmingState.InWaterSurface))
            //{
            //SetSwimStateDeepWater();
            //}

            if (m_SwimState == SwimmingState.InDeepWater)
            {
                if (transform.position.y >= (surface - 0.05f))
                {
                    SetSwimStateSurfaceWater();
                }
            }

            /*if((surface - m_Transform.position.y) >  0.35f  && (m_SwimState == SwimmingState.None))
             *          {
             *                  SetSwimStateShallowWater();
             *          }*/

            if (m_SwimState == SwimmingState.InWaterSurface)
            {
                //Grab ledge and get outof water
                if (m_bStandingUp || m_bPullingUp)
                {
                    //m_SwimState = SwimmingState.None;
                }
            }

            //define shallow water analyzing tub depth


            //Debug.Log("room.m_Tr2Room.info.yTop " + (-room.m_Tr2Room.info.yTop * Settings.SceneScaling));
            //Debug.Log("room.m_Tr2Room.info.yBottom " + (-room.m_Tr2Room.info.yBottom * Settings.SceneScaling));
        }
        else
        {
            //SetSwimStateNone();
            //StopImmediate();
        }


        /*
         * [from state jumping/diving]
         *
         * dive in shallow water ->
         *
         * dive in deep water - >
         *
         * */

        /*
         *
         * [from state in shallow water]
         *
         * Jump->
         * trytorun->
         *
         * */


        /*
         *
         * [from state deep water]
         *
         * swim->
         * swim to shallow water->
         * move to surface->
         *
         * */


        /*
         *
         * [from state surface]
         *
         * move-> grab platform -> pull up
         *
         * */

        //Debug.Log("Swimm State:" + m_SwimState);
    }