/*
     * \brief Works out if a value is almost another value (for floating point accuracy)
     */
    public void CallOnCollisionEnter(Collision collision)
    {
        m_collisionState = CollisionState.None;

        foreach (ContactPoint contact in collision)
        {
            m_platform = contact.otherCollider.gameObject.GetComponent <CSceneObjectPlatform>();
            if (m_platform != null)
            {
                m_platform.resetDeltaA();
            }
            if (isNearly(contact.normal.y, 1.0f, 0.2f))
            {
                m_collisionState = CollisionState.OnFloor;

                // are we on a special material?
                m_footMaterial = FootMaterial.Stone;
                if (contact.otherCollider.tag == "Wood Object")
                {
                    m_footMaterial = FootMaterial.Wood;
                }
                else if (contact.otherCollider.tag == "Metal Object")
                {
                    m_footMaterial = FootMaterial.Metal;
                }
            }
            else if (isNearly(contact.normal.y, -1.0f, 0.2f))
            {
                m_collisionState = CollisionState.OnRoof;
            }
            else
            {
                m_collisionState    = CollisionState.OnWall;
                m_ladderClimb.State = LadderState.None;
            }
        }

        if (m_collisionState == CollisionState.OnFloor)
        {
            if (m_jumpState != JumpState.Landed)
            {
                m_player.GetPlayerAnimation().PlayFootstepAudio(m_footMaterial);
            }

            m_jumpState         = JumpState.Landed;
            m_ladderClimb.State = LadderState.None;

            if (m_player.GetPlayerState() != PlayerState.Turning)
            {
                m_player.SetPlayerState(PlayerState.Standing);
            }

            //m_ledgeGrabBox.collider.enabled = true;
        }
    }
Exemple #2
0
    void OnGUI()
    {
        if (!m_visible || m_player == null)
        {
            return;
        }

        m_information.Clear();
        m_information.Add("Player Position: " + m_player.transform.position.ToString());
        m_information.Add("Player Alpha: " + m_player.CurrentPlayerAlpha.ToString());
        m_information.Add("Player State: " + m_player.GetPlayerState().ToString());
        m_information.Add("Collision State: " + m_player.Physics.CurrentCollisionState.ToString());
        m_information.Add("Jump State: " + m_player.Physics.JumpType.ToString());
        m_information.Add("Ladder State: " + m_player.Physics.LadderClimb.State.ToString());
        m_information.Add("----------");
        m_information.Add("Direction: " + m_player.Physics.Direction.ToString());
        m_information.Add("Moving Direction: " + m_player.Physics.MovingDirection.ToString());
        m_information.Add("----------");
        m_information.Add("Animation: " + m_player.CurrentAnimation());

        Rect labelPosition = new Rect(4, 4, 512, 512);

        GUI.Label(labelPosition, "Player Debug Information");
        labelPosition.y += 20;

        foreach (string info in m_information)
        {
            labelPosition.y += 20;
            GUI.Label(labelPosition, info);
        }
    }
    void OnGUI()
    {
        if (!Application.isEditor)
        {
            return;
        }

        if (!m_visible || m_player == null)
        {
            return;
        }

        if (m_player.CurrentGameState == GameState.Paused)
        {
            return;
        }

        m_information.Clear();
        m_information.Add("FPS: " + m_fps);
        m_information.Add("----------");
        m_information.Add("Player Position: " + m_player.transform.position.ToString());
        m_information.Add("Player Alpha: " + m_player.CurrentPlayerAlpha.ToString());
        m_information.Add("----------");
        m_information.Add("Player State: " + m_player.GetPlayerState().ToString());
        m_information.Add("Collision State: " + m_player.Physics.CurrentCollisionState.ToString());
        m_information.Add("Jump State: " + m_player.Physics.JumpType.ToString());
        m_information.Add("Ladder State: " + m_player.Physics.GetLadder.state.ToString());
        m_information.Add("----------");
        m_information.Add("Ladder Moving: " + m_player.Physics.GetLadder.moving.ToString());
        m_information.Add("Ladder Offset: " + m_player.Physics.GetLadder.offset.ToString());
        m_information.Add("Ladder Direction: " + m_player.Physics.GetLadder.direction.ToString());
        m_information.Add("----------");
        m_information.Add("Direction: " + m_player.Physics.Direction.ToString());
        m_information.Add("Moving Direction: " + m_player.Physics.MovingDirection.ToString());
        m_information.Add("----------");
        m_information.Add("Animation: " + m_player.CurrentAnimation());
        m_information.Add("----------");
        m_information.Add("Current Level: " + m_player.CurrentLevel);

        Rect labelPosition = new Rect(4, 4, 512, 512);

        GUI.Label(labelPosition, "Player Debug Information");
        labelPosition.y += 20;

        foreach (string info in m_information)
        {
            labelPosition.y += 20;
            GUI.Label(labelPosition, info);
        }
    }
Exemple #4
0
    /*
     * \brief Called once per frame
     */
    public void FixedUpdate()
    {
        int   maxFramesIgnorePos = 1;
        float maxPosJumpFactor   = 0.5f;      //0.05f;
        bool  posIgnored         = true;

        if (m_countIgnoredFrames < maxFramesIgnorePos)
        {
            if (m_currentTransform.position.y > m_averagePos.y - maxPosJumpFactor && m_currentTransform.position.y < m_averagePos.y + maxPosJumpFactor)
            {
                m_storedPositions.Add(m_currentTransform.position);
                posIgnored = false;
            }
        }
        else
        {
            m_storedPositions.Add(m_currentTransform.position);
            posIgnored = false;
        }

        if (posIgnored)
        {
            m_countIgnoredFrames++;
        }
        else
        {
            m_countIgnoredFrames = 0;
        }

        int removeAmount = 2;

        while (m_storedPositions.Count > MaxPositionsStored)
        {
            m_storedPositions.RemoveAt(0);
            removeAmount--;
            if (removeAmount <= 0)
            {
                break;
            }
        }

        Vector3 sumPositions = new Vector3(0.0f, 0.0f, 0.0f);

        foreach (Vector3 pos in m_storedPositions)
        {
            sumPositions += pos;
        }
        Vector3 avgPosition = sumPositions / m_storedPositions.Count;

        this.TendToMaxOffset(m_playerEntity.Physics.Direction);
        m_averagePos = avgPosition;

        float   adjustedCameraHeight = avgPosition.y + CameraElevation;
        Vector3 camPosition;

        if (m_playerEntity.Physics.InsideTower)
        {
            Vector3 playerToCamera     = new Vector3(0.0f, adjustedCameraHeight, 0.0f) - avgPosition;
            Vector3 normPlayerToCamera = Vector3.Normalize(playerToCamera);
            camPosition = avgPosition + (normPlayerToCamera * DistanceFromPlayer);
        }
        else
        {
            Vector3 playerToOrigin     = new Vector3(0.0f, avgPosition.y, 0.0f) - avgPosition;
            Vector3 normPlayerToOrigin = Vector3.Normalize(playerToOrigin);
            camPosition    = avgPosition - (normPlayerToOrigin * DistanceFromPlayer);
            camPosition.y += CameraElevation;
        }

        m_storedCameraPositions.Add(camPosition);
        removeAmount = 2;
        while (m_storedCameraPositions.Count > MaxCamPositionsStored)
        {
            m_storedCameraPositions.RemoveAt(0);
            removeAmount--;
            if (removeAmount <= 0)
            {
                break;
            }
        }

        Vector3 sumCamPositions = new Vector3(0.0f, 0.0f, 0.0f);

        foreach (Vector3 pos in m_storedCameraPositions)
        {
            sumCamPositions += pos;
        }
        Vector3 avgCamPosition = sumCamPositions / m_storedCameraPositions.Count;

        if (m_playerEntity.GetPlayerState() != PlayerState.FallingFromTower)
        {
            m_transform.position = avgCamPosition;
        }

        this.SetLookAt(avgPosition);
    }
Exemple #5
0
    public bool CheckLadder(Collider collision)
    {
        if (this.name == "LadderBASE" && collision.name == "Player Spawn")
        {
            GameObject playerObject = collision.gameObject;
            if (playerObject == null)
            {
                return(false);
            }

            CEntityPlayer player = playerObject.GetComponent <CEntityPlayer>();
            if (player == null)
            {
                return(false);
            }

            LadderState currentLadderState = player.Physics.GetLadder.state;

            if (currentLadderState == LadderState.None || currentLadderState == LadderState.OnMiddle || currentLadderState == LadderState.JumpingOff)
            {
                player.Physics.GetLadder.state = LadderState.AtBase;
            }

            return(true);
        }

        if (this.name == "LadderMID" && collision.name == "Player Spawn")
        {
            GameObject playerObject = collision.gameObject;
            if (playerObject == null)
            {
                return(false);
            }

            CEntityPlayer player = playerObject.GetComponent <CEntityPlayer>();
            if (player == null)
            {
                return(false);
            }

            LadderState currentLadderState = player.Physics.GetLadder.state;

            if (player.GetPlayerState() == PlayerState.OnLadder || currentLadderState == LadderState.None)
            {
                player.Physics.GetLadder.state = LadderState.OnMiddle;
                player.SetPlayerState(PlayerState.OnLadder);
                player.Physics.CurrentCollisionState = CollisionState.None;
            }

            return(true);
        }

        if (this.name == "LadderTOP" && collision.name == "Player Spawn")
        {
            GameObject playerObject = collision.gameObject;
            if (playerObject == null)
            {
                return(false);
            }

            CEntityPlayer player = playerObject.GetComponent <CEntityPlayer>();
            if (player == null)
            {
                return(false);
            }

            LadderState currentLadderState = player.Physics.GetLadder.state;

            if (currentLadderState == LadderState.OnMiddle)
            {
                player.Physics.GetLadder.state = LadderState.OnTop;
                player.SetPlayerState(PlayerState.OnLadder);
                player.Physics.CurrentCollisionState = CollisionState.None;
            }

            return(true);
        }

        return(false);
    }
Exemple #6
0
    public static bool CheckLedgeGrab(Collision collision)
    {
        foreach (ContactPoint contact in collision)
        {
            Collider     ledgeGrab  = null;
            CSceneObject sceneLedge = null;

            if (contact.otherCollider != null && contact.otherCollider.gameObject.name == "Ledge_Grab_Detection")
            {
                ledgeGrab = contact.otherCollider;

                if (contact.thisCollider != null && contact.thisCollider.gameObject != null)
                {
                    sceneLedge = contact.thisCollider.gameObject.GetComponent <CSceneObject>();
                }
            }
            else if (contact.thisCollider != null && contact.thisCollider.gameObject.name == "Ledge_Grab_Detection")
            {
                ledgeGrab = contact.thisCollider;

                if (contact.otherCollider != null && contact.otherCollider.gameObject != null)
                {
                    sceneLedge = contact.otherCollider.gameObject.GetComponent <CSceneObject>();
                }
            }

            if (sceneLedge == null || !sceneLedge.CanLedgeGrab)
            {
                if (ledgeGrab != null)
                {
                    ledgeGrab.enabled = false;
                }
                continue;
            }

            if (ledgeGrab != null)
            {
                if (CPlayerPhysics.isNearly(contact.normal.normalized.y, -1.0f, 0.1f))
                {
                    // player hit the ledge grab area
                    GameObject player = contact.otherCollider.gameObject.transform.parent.gameObject;
                    if (player != null)
                    {
                        CEntityPlayer playerEntity = player.GetComponent <CEntityPlayer>();
                        if (playerEntity != null &&
                            playerEntity.GetPlayerState() != PlayerState.LedgeHang &&
                            playerEntity.GetPlayerState() != PlayerState.LedgeClimb &&
                            playerEntity.GetPlayerState() != PlayerState.LedgeClimbComplete
                            )
                        {
                            CPlayerPhysics phy = playerEntity.Physics;
                            phy.SetLedgeGrabState(playerEntity, PlayerState.LedgeHang);
                            contact.otherCollider.enabled = false;
                            return(true);
                        }
                    }
                }
                else
                {
                    ledgeGrab.enabled = false;
                    return(false);
                }
            }
        }

        return(false);
    }
    /*
     * \brief Works out if a value is almost another value (for floating point accuracy)
     */
    public void CallOnCollisionEnter(Collision collision)
    {
        m_collisionState = CollisionState.None;

        foreach (ContactPoint contact in collision)
        {
            m_platform = contact.otherCollider.gameObject.GetComponent <CSceneObjectPlatform>();
            if (m_platform != null)
            {
                m_platform.resetDeltaA();
            }
            if (isNearly(contact.normal.y, 1.0f, 0.2f))
            {
                m_collisionState = CollisionState.OnFloor;

                if (m_player.GetPlayerState() == PlayerState.OnLadder)
                {
                    GetLadder.state = LadderState.AtBase;
                    m_player.SetPlayerState(PlayerState.Standing);
                }

                // are we on a special material?
                m_footMaterial = FootMaterial.Stone;
                if (contact.otherCollider.tag == "Wood Object")
                {
                    m_footMaterial = FootMaterial.Wood;
                }
                else if (contact.otherCollider.tag == "Metal Object")
                {
                    m_footMaterial = FootMaterial.Metal;
                }
            }
            else if (isNearly(contact.normal.y, -1.0f, 0.2f))
            {
                m_collisionState = CollisionState.OnRoof;
                if (contact.otherCollider != null && contact.otherCollider.GetComponent <CSceneObjectPlatform>() != null)
                {
                    m_player.PushPlayerFromTower();
                }
            }
            else
            {
                if (m_player.GetPlayerState() != PlayerState.OnLadder)
                {
                    m_collisionState = CollisionState.OnWall;
                }
            }
        }

        if (m_collisionState == CollisionState.OnFloor)
        {
            if (m_jumpState != JumpState.Landed)
            {
                m_player.GetPlayerAnimation().PlayFootstepAudio(m_footMaterial);
            }

            m_jumpState = JumpState.Landed;

            if (GetLadder.state == LadderState.JumpingOff)
            {
                GetLadder.state = LadderState.None;
            }

            if (m_player.GetPlayerState() != PlayerState.Turning && m_player.GetPlayerState() != PlayerState.OnLadder && !m_player.PullingLever(false))
            {
                m_player.SetPlayerState(PlayerState.Standing);
            }
        }
    }
    void FixedUpdate()
    {
        //test if in arc of player
        //Vector3 adjustedOriginPlayer = new Vector3(0.0f, m_playerEntity.transform.position.y, 0.0f);
        //Vector3 playerOriginVec = m_playerEntity.transform.position - adjustedOriginPlayer;
        //Vector3 adjustedOriginShip = new Vector3(0.0f, this.transform.position.y, 0.0f);
        //Vector3 shipOriginVec = this.transform.position - adjustedOriginShip;

        if (m_playerEntity)
        {
            //float shipDotPlayer = Vector3.Dot(playerOriginVec, shipOriginVec);
            Vector3 shipToPlayer       = m_playerEntity.transform.position - this.transform.position;
            float   distanceFromPlayer = shipToPlayer.magnitude;
            if (distanceFromPlayer < firingArcLength)
            {
                m_isFiring = true;
            }
            else
            {
                m_isFiring = false;
            }
            testLength = distanceFromPlayer;

            //If player falling from tower, reset ship position
            if (m_playerEntity.GetPlayerState() == PlayerState.FallingFromTower)
            {
                this.transform.position = m_initialTransform.position;
                this.transform.rotation = m_initialTransform.rotation;
            }

            //update list of player Y pos
            if (m_playerEntity.GetPlayerState() != PlayerState.Jumping)
            {
                float playerY = m_playerTransform.position.y;
                m_storedYPositions.Add(playerY);
                m_storedYPositions.RemoveAt(0);
            }

            //Calculate Y bos based on past NumYPositions frames
            float sumYPos = 0.0f;
            foreach (float yPos in m_storedYPositions)
            {
                sumYPos += yPos;
            }
            float averageY = 0.0f;
            if (NumYPositions > 0)
            {
                averageY = sumYPos / NumYPositions;
            }
            float correctedY = averageY + YOffset;
            float speed      = 0.0f;
            if (m_isFiring)
            {
                speed = FiringSpeed * m_cutsceneSpeedMod;
            }
            else
            {
                speed = CirclingSpeed * m_cutsceneSpeedMod;
            }

            //update ship position
            Transform currentTransform = this.transform;
            Vector3   origin           = new Vector3(0.0f, 0.0f, 0.0f);
            Vector3   up = new Vector3(0.0f, 1.0f, 0.0f);
            this.transform.RotateAround(origin, up, speed * 0.1f);

            Vector3 pos = this.transform.position;
            pos.y = correctedY;
            this.transform.position = pos;

            if (m_fireTimer >= RateOfFire)
            {
                if (m_isFiring)
                {
                    FireCannon();
                }
                m_fireTimer = 0.0f;
            }
            else
            {
                m_fireTimer += Time.deltaTime;
            }
        }
    }