예제 #1
0
    public void PlayFootstepAudio(FootMaterial material)
    {
        AudioClip[] clips = FootstepsStone;
        switch (material)
        {
        case FootMaterial.Wood:
            clips = FootstepsWood;
            break;

        case FootMaterial.Metal:
            clips = FootstepsMetal;
            break;
        }

        int noofAudioClips = clips.Length;

        if (noofAudioClips != 0)
        {
            int audioIndex = Random.Range(0, noofAudioClips);
            if (!m_audio.isPlaying)
            {
                m_audio.clip = clips[audioIndex];
                m_audio.Play();
            }
        }
    }
    /*
     * \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;
        }
    }
 public void OnFixedUpdate(ref GruntState playerState, CGruntPhysics physics, FootMaterial footMaterial)
 {
     if (playerState == GruntState.Walking)
     {
         m_currentAnimation = "walk";
         if (!m_animation.IsPlaying("walk"))
         {
             m_animation.CrossFade("walk", 0.2f);
             PlayFootstepAudio(footMaterial);
         }
     }
     else if (playerState == GruntState.Turning)
     {
         m_currentAnimation = "running-turn";
         if (!m_animation.IsPlaying("running-turn") && !m_startedTurningRound)
         {
             m_startedTurningRound = true;
             m_animation["running-turn"].speed = 1.2f;
             m_animation.CrossFade("running-turn");
         }
         else if (!m_animation.IsPlaying("running-turn"))
         {
             m_startedTurningRound = false;
             playerState = GruntState.Walking;
         }
     }
     else if (playerState == GruntState.Standing)
     {
         if (!m_animation.IsPlaying(m_lastKnownIdle))
         {
             m_currentAnimation = "idle-" + Random.Range(0, 2);
             m_lastKnownIdle = m_currentAnimation;
             m_animation[m_currentAnimation].speed = Random.Range(10, 30) / 100.0f;
             m_animation.CrossFade(m_currentAnimation);
         }
     }
     else if (playerState == GruntState.Jumping)
     {
         m_currentAnimation = "run-jump";
         if (!m_animation.IsPlaying("run-jump"))
             m_animation.Play("run-jump");
     }
     else if (playerState == GruntState.FallJumping)
     {
         m_currentAnimation = "falling";
         if (!m_animation.IsPlaying("falling"))
             m_animation.CrossFade("falling");
     }
     else if (playerState == GruntState.FallingFromTower)
     {
         m_currentAnimation = "falling";
         if (!m_animation.IsPlaying("falling"))
             m_animation.CrossFade("falling");
     }
 }
예제 #4
0
    public void PlayFootstepAudio(FootMaterial material)
    {
        AudioClip[] clips = FootstepsStone;
        switch (material)
        {
        case FootMaterial.Wood:
            clips = FootstepsWood;
            break;

        case FootMaterial.Metal:
            clips = FootstepsMetal;
            break;
        }

        PlayRandomAudio(clips, 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;

                // 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;
        }
    }
예제 #6
0
 public void OnFixedUpdate(ref GruntState playerState, CGruntPhysics physics, FootMaterial footMaterial)
 {
     if (playerState == GruntState.Walking)
     {
         m_currentAnimation = "walk";
         if (!m_animation.IsPlaying("walk"))
         {
             m_animation.CrossFade("walk", 0.2f);
             PlayFootstepAudio(footMaterial);
         }
     }
     else if (playerState == GruntState.Turning)
     {
         m_currentAnimation = "running-turn";
         if (!m_animation.IsPlaying("running-turn") && !m_startedTurningRound)
         {
             m_startedTurningRound             = true;
             m_animation["running-turn"].speed = 1.2f;
             m_animation.CrossFade("running-turn");
         }
         else if (!m_animation.IsPlaying("running-turn"))
         {
             m_startedTurningRound = false;
             playerState           = GruntState.Walking;
         }
     }
     else if (playerState == GruntState.Standing)
     {
         if (!m_animation.IsPlaying(m_lastKnownIdle))
         {
             m_currentAnimation = "idle-" + Random.Range(0, 2);
             m_lastKnownIdle    = m_currentAnimation;
             m_animation[m_currentAnimation].speed = Random.Range(10, 30) / 100.0f;
             m_animation.CrossFade(m_currentAnimation);
         }
     }
     else if (playerState == GruntState.Jumping)
     {
         m_currentAnimation = "run-jump";
         if (!m_animation.IsPlaying("run-jump"))
         {
             m_animation.Play("run-jump");
         }
     }
     else if (playerState == GruntState.FallJumping)
     {
         m_currentAnimation = "falling";
         if (!m_animation.IsPlaying("falling"))
         {
             m_animation.CrossFade("falling");
         }
     }
     else if (playerState == GruntState.FallingFromTower)
     {
         m_currentAnimation = "falling";
         if (!m_animation.IsPlaying("falling"))
         {
             m_animation.CrossFade("falling");
         }
     }
 }
    /*
     * \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);
            }
        }
    }
예제 #8
0
/*
 * \brief Called whilst a collision is taking place
 */
    public void CallOnCollisionStay(Collision collision, ref GruntState playerState, ref float playerAlpha)
    {
        m_collisionState = CollisionState.None;

        foreach (ContactPoint contact in collision)
        {
            Debug.DrawRay(contact.point, contact.normal);
            //
            if (contact.otherCollider != null && contact.otherCollider.gameObject != null)
            {
                CSceneObjectPlatform platform = contact.otherCollider.gameObject.GetComponent <CSceneObjectPlatform>();
                if (platform != null && m_platform == null)
                {
                    m_platform = platform;
                    m_platform.resetDeltaA();
                }
            }

            //
            CSceneObject obj = null;
            if (contact.otherCollider)
            {
                obj = contact.otherCollider.gameObject.GetComponent <CSceneObject>();
                if (obj == null && contact.otherCollider.gameObject.transform.parent != null)
                {
                    GameObject parent = contact.otherCollider.gameObject.transform.parent.gameObject;
                    if (parent != null)
                    {
                        obj = parent.GetComponent <CSceneObject>();
                    }
                }
            }

            // floor check
            else if (isNearly(contact.normal.y, 1.0f, 0.8f))
            {
                m_collisionState = CollisionState.OnFloor;
                if (!isNearly(contact.normal.y, 1.0f, 0.15f) && collision.contacts.Length == 1)
                {
                    if (m_grunt.GetGruntState() == GruntState.Walking)
                    {
                        if (m_grunt.GetGruntPlayerDetected())
                        {
                            m_velocity = (m_movingDirection * 0.6f);
                        }
                        else
                        {
                            m_velocity = (m_movingDirection * 0.15f);
                        }
                        m_velocityLockTimer = (Time.time * 1000.0f);
                    }
                }
                if (contact.otherCollider)
                {
                    // 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;
                    }
                }
            }
            // head check
            else if (isNearly(contact.normal.y, -1.0f, 0.1f))
            {
                m_collisionState = CollisionState.OnRoof;
            }
            // wall check
            else
            {
                if (isFacingCollision(m_movingDirection, m_body.transform.position, contact.point, playerAlpha))
                {
                    m_collisionState = CollisionState.OnWall;
                    break;
                }
            }
        }

        if (m_collisionState == CollisionState.OnWall && m_jumpState == JumpState.Jumping && playerState != GruntState.WallJumpStart)
        {
            m_velocity = -(m_movingDirection * 0.15f);
        }

        if (m_collisionState == CollisionState.OnFloor && ((Time.time * 1000.0f) - m_jumpTimer > 200.0f))
        {
            m_jumpState = JumpState.Landed;

            if (m_grunt.GetGruntState() != GruntState.Turning)
            {
                m_grunt.SetGruntState(GruntState.Standing);
            }
        }
    }
예제 #9
0
    /*
     * \brief Works out if a value is almost another value (for floating point accuracy)
     */
    public void CallOnCollisionEnter(Collision collision, bool playerDetected)
    {
        m_collisionState = CollisionState.None;

        foreach (ContactPoint contact in collision)
        {
            m_platform = contact.otherCollider.gameObject.GetComponent <CSceneObjectPlatform>();
            if (m_platform != null)
            {
                m_platform.resetDeltaA();
            }
            else 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;
            }
        }

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

            m_jumpState = JumpState.Landed;
        }
        if ((m_collisionState == CollisionState.OnWall || collision.collider.gameObject.name == "GruntBarrier") && m_grunt.GetGruntState() != GruntState.Turning && m_grunt.GetGruntState() != GruntState.Attacking)
        {
            if (!playerDetected)
            {
                m_grunt.SetGruntState(GruntState.Turning);
                if (m_movingDirection == 1)
                {
                    m_movingDirection = -1;
                    m_direction       = -1;
                }
                else if (m_movingDirection == -1)
                {
                    m_movingDirection = 1;
                    m_direction       = 1;
                }
            }
            else
            {
                m_grunt.SetGruntState(GruntState.Standing);
            }
        }
    }
    public void OnFixedUpdate(ref PlayerState playerState, LadderState ladderState, FootMaterial footMaterial)
    {
        if (playerState == PlayerState.Walking)
        {
            m_currentAnimation = "Run";
            if (!m_animation.IsPlaying("Run"))
            {
                m_animation.CrossFade("Run", 0.2f);
                PlayFootstepAudio(footMaterial);
            }
        }
        else if (playerState == PlayerState.Turning)
        {
            m_currentAnimation = "Turning Around";
            if (!m_animation.IsPlaying("Running Turn") && !m_startedTurningRound)
            {
                m_startedTurningRound = true;
                m_animation.CrossFade("Running Turn");
            }
            else if (!m_animation.IsPlaying("Running Turn"))
            {
                m_startedTurningRound = false;
                playerState = PlayerState.Walking;
            }
        }
        else if (playerState == PlayerState.Standing)
        {
            m_currentAnimation = "Idle";
            m_animation["Idle Simple"].speed = 0.2f;
            if (!m_animation.IsPlaying("Idle Simple"))
                m_animation.CrossFade("Idle Simple");
        }
        else if (playerState == PlayerState.Jumping)
        {
            m_currentAnimation = "Running";
            if (!m_animation.IsPlaying("Running Jump (NEW)"))
                m_animation.Play("Running Jump (NEW)");
        }
        else if (playerState == PlayerState.FallJumping)
        {
            m_currentAnimation = "Falling";
            if (!m_animation.IsPlaying("Falling Loop"))
                m_animation.CrossFade("Falling Loop");
        }
        else if (playerState == PlayerState.LedgeHang)
        {
            m_currentAnimation = "Ledge Hang";
            if (!m_animation.IsPlaying("Wall Hang Idle")) {
                m_animation.CrossFade("Wall Hang Idle");
                m_startedLedgeClimb = false;
            }
        }
        else if (playerState == PlayerState.LedgeClimb)
        {
            m_currentAnimation = "Ledge Climbing";
            if (!m_animation.IsPlaying("Climb from Free Hang") && !m_startedLedgeClimb) {
                m_animation.CrossFade("Climb from Free Hang");
                m_startedLedgeClimb = true;
            }
            else if (m_startedLedgeClimb == true && !m_animation.IsPlaying("Climb from Free Hang")) {
                playerState = PlayerState.LedgeClimbComplete;
                m_startedLedgeClimb = false;
            }
        }
        else if (playerState == PlayerState.FallingFromTower)
        {
            m_currentAnimation = "Falling";
            if (!m_animation.IsPlaying("Falling Loop"))
                m_animation.CrossFade("Falling Loop");
        }
        else if (playerState == PlayerState.UpALadder)
        {
            float upDown = Input.GetAxis("Vertical");

            m_currentAnimation = "Ladder";

            if ((upDown != 0.0f && ladderState != LadderState.AtTop) || (ladderState == LadderState.AtTop && upDown < 0))
            {
                bool forceAnimationChange = upDown > 0.0f && m_animation["Ladder Up"].speed > 0.0f ? false : true;
                if (!m_animation.IsPlaying("Ladder Up") || forceAnimationChange)
                {
                    m_animation["Ladder Up"].speed = upDown > 0.0f ? 2.0f : -2.0f;
                    m_animation.Play("Ladder Up");
                }

                if (m_animation.IsPlaying("Ladder Up"))
                {
                    PlayFootstepAudio(FootMaterial.Metal);
                }

            }
            else
            {
                m_animation["Ladder Up"].speed = 0.0f;
                if (!m_animation.IsPlaying("Ladder Up"))
                    m_animation.Play("Ladder Up");
            }
        }
    }
    /*
     * \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);
            }
        }
    }
    public void PlayFootstepAudio(FootMaterial material)
    {
        AudioClip[] clips = FootstepsStone;
        switch(material)
        {
        case FootMaterial.Wood:
            clips = FootstepsWood;
            break;
        case FootMaterial.Metal:
            clips = FootstepsMetal;
            break;
        }

        int noofAudioClips = clips.Length;
        if (noofAudioClips != 0)
        {
            int audioIndex = Random.Range(0, noofAudioClips);
            if (!m_audio.isPlaying)
            {
                m_audio.clip = clips[audioIndex];
                m_audio.Play();
            }
        }
    }
예제 #13
0
    public void OnFixedUpdate(ref PlayerState playerState, LadderState ladderState, FootMaterial footMaterial)
    {
        if (playerState == PlayerState.Walking)
        {
            m_currentAnimation = "Run";
            if (!m_animation.IsPlaying("Run"))
            {
                m_animation.CrossFade("Run", 0.2f);
                PlayFootstepAudio(footMaterial);
            }
        }
        else if (playerState == PlayerState.Turning)
        {
            m_currentAnimation = "Turning Around";
            if (!m_animation.IsPlaying("Running Turn") && !m_startedTurningRound)
            {
                m_startedTurningRound = true;
                m_animation.CrossFade("Running Turn");
            }
            else if (!m_animation.IsPlaying("Running Turn"))
            {
                m_startedTurningRound = false;
                playerState           = PlayerState.Walking;
            }
        }
        else if (playerState == PlayerState.Standing)
        {
            m_currentAnimation = "Idle";
            m_animation["Idle Simple"].speed = 0.2f;
            if (!m_animation.IsPlaying("Idle Simple"))
            {
                m_animation.CrossFade("Idle Simple");
            }
        }
        else if (playerState == PlayerState.Jumping)
        {
            m_currentAnimation = "Running";
            if (!m_animation.IsPlaying("Running Jump (NEW)"))
            {
                m_animation.Play("Running Jump (NEW)");
            }
        }
        else if (playerState == PlayerState.FallJumping)
        {
            m_currentAnimation = "Falling";
            if (!m_animation.IsPlaying("Falling Loop"))
            {
                m_animation.CrossFade("Falling Loop");
            }
        }
        else if (playerState == PlayerState.LedgeHang)
        {
            m_currentAnimation = "Ledge Hang";
            if (!m_animation.IsPlaying("Wall Hang Idle"))
            {
                m_animation.CrossFade("Wall Hang Idle");
                m_startedLedgeClimb = false;
            }
        }
        else if (playerState == PlayerState.LedgeClimb)
        {
            m_currentAnimation = "Ledge Climbing";
            if (!m_animation.IsPlaying("Climb from Free Hang") && !m_startedLedgeClimb)
            {
                m_animation.CrossFade("Climb from Free Hang");
                m_startedLedgeClimb = true;
            }
            else if (m_startedLedgeClimb == true && !m_animation.IsPlaying("Climb from Free Hang"))
            {
                playerState         = PlayerState.LedgeClimbComplete;
                m_startedLedgeClimb = false;
            }
        }
        else if (playerState == PlayerState.FallingFromTower)
        {
            m_currentAnimation = "Falling";
            if (!m_animation.IsPlaying("Falling Loop"))
            {
                m_animation.CrossFade("Falling Loop");
            }
        }
        else if (playerState == PlayerState.UpALadder)
        {
            float upDown = Input.GetAxis("Vertical");

            m_currentAnimation = "Ladder";

            if ((upDown != 0.0f && ladderState != LadderState.AtTop) || (ladderState == LadderState.AtTop && upDown < 0))
            {
                bool forceAnimationChange = upDown > 0.0f && m_animation["Ladder Up"].speed > 0.0f ? false : true;
                if (!m_animation.IsPlaying("Ladder Up") || forceAnimationChange)
                {
                    m_animation["Ladder Up"].speed = upDown > 0.0f ? 2.0f : -2.0f;
                    m_animation.Play("Ladder Up");
                }

                if (m_animation.IsPlaying("Ladder Up"))
                {
                    PlayFootstepAudio(FootMaterial.Metal);
                }
            }
            else
            {
                m_animation["Ladder Up"].speed = 0.0f;
                if (!m_animation.IsPlaying("Ladder Up"))
                {
                    m_animation.Play("Ladder Up");
                }
            }
        }
    }
    /*
     * \brief Works out if a value is almost another value (for floating point accuracy)
    */
    public void CallOnCollisionEnter(Collision collision, bool playerDetected)
    {
        m_collisionState = CollisionState.None;

        foreach (ContactPoint contact in collision)
        {
            m_platform = contact.otherCollider.gameObject.GetComponent<CSceneObjectPlatform>();
            if (m_platform != null) {
                m_platform.resetDeltaA();
            }
            else 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;
            }
        }

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

            m_jumpState = JumpState.Landed;
        }
        if ( (m_collisionState == CollisionState.OnWall || collision.collider.gameObject.name=="GruntBarrier") &&  m_grunt.GetGruntState() != GruntState.Turning && m_grunt.GetGruntState() != GruntState.Attacking)
        {
            if( !playerDetected )
            {
                m_grunt.SetGruntState( GruntState.Turning );
                if( m_movingDirection == 1)
                {
                    m_movingDirection = -1;
                    m_direction = -1;
                }
                else if( m_movingDirection == -1 )
                {
                    m_movingDirection = 1;
                    m_direction = 1;
                }
            }
            else
            {
                m_grunt.SetGruntState( GruntState.Standing );
            }
        }
    }
    /*
     * \brief Called whilst a collision is taking place
    */
    public void CallOnCollisionStay(Collision collision, ref PlayerState playerState, ref float playerAlpha)
    {
        m_collisionState = CollisionState.None;

        foreach (ContactPoint contact in collision)
        {
            Debug.DrawRay(contact.point, contact.normal);

            //
            if (contact.otherCollider != null && contact.otherCollider.gameObject != null)
            {
                CSceneObjectPlatform platform = contact.otherCollider.gameObject.GetComponent<CSceneObjectPlatform>();
                if (platform != null && m_platform == null) {
                    m_platform = platform;
                    m_platform.resetDeltaA();
                }
            }

            //
            CSceneObject obj = null;
            if (contact.otherCollider)
            {
                obj = contact.otherCollider.gameObject.GetComponent<CSceneObject>();
                if (obj == null && contact.otherCollider.gameObject.transform.parent != null) {
                    GameObject parent = contact.otherCollider.gameObject.transform.parent.gameObject;
                    if (parent != null) {
                        obj = parent.GetComponent<CSceneObject>();
                    }
                }
            }

            if (contact.thisCollider != null && contact.thisCollider.gameObject != null && contact.thisCollider.gameObject.name == "Ledge_Grab_Detection" && (obj == null || obj.CanLedgeGrab))
            {
                if(CSceneObject.CheckLedgeGrab(collision))
                    continue;
            }

            if (contact.otherCollider != null && contact.otherCollider.gameObject != null && contact.otherCollider.gameObject.name == "Ledge_Grab_Detection" && (obj == null || obj.CanLedgeGrab))
            {
                if (CSceneObject.CheckLedgeGrab(collision))
                    continue;
            }

            // wall jumping
            if (obj != null && obj.CanWallJump == true && m_jumpState != JumpState.Landed && !isNearly(contact.normal.y, 1.0f, 0.2f) && !isNearly(contact.normal.y, -1.0f, 0.1f))
            {
                m_collisionState = CollisionState.OnWall;
                playerState = PlayerState.WallJumpStart;
                m_jumpTimer = (Time.time * 1000.0f);
                m_body.constraints = RigidbodyConstraints.FreezeAll;
                m_velocity = 0.0f;
                m_wallJump.StartHangTime = Time.time * 1000.0f;
            }
            // floor check
            else if (isNearly(contact.normal.y, 1.0f, 0.8f))
            {
                m_collisionState = CollisionState.OnFloor;
                if (!isNearly(contact.normal.y, 1.0f, 0.15f) && collision.contacts.Length == 1)
                {
                    m_velocity = (m_movingDirection * 0.15f);
                    m_velocityLockTimer = (Time.time * 1000.0f);
                }

                // 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;
            }
            // head check
            else if (isNearly(contact.normal.y, -1.0f, 0.1f))
            {
                m_collisionState = CollisionState.OnRoof;
            }
            // wall check
            else
            {
                if (isFacingCollision(m_movingDirection, m_body.transform.position, contact.point, playerAlpha)) {
                    m_collisionState = CollisionState.OnWall;
                    break;
                }
            }
        }

        if (m_collisionState == CollisionState.OnWall && m_jumpState == JumpState.Jumping && playerState != PlayerState.WallJumpStart)
        {
            m_velocity = -(m_movingDirection * 0.15f);
        }

        if (m_collisionState == CollisionState.OnFloor && ((Time.time * 1000.0f) - m_jumpTimer > 200.0f))
        {
            m_jumpState = JumpState.Landed;

            if (m_ladderClimb.State != LadderState.AtBase)
            {
                m_ladderClimb.State = LadderState.None;
            }
            else
            {
                playerState = PlayerState.UpALadder;
            }

            if (m_player.GetPlayerState() != PlayerState.Turning) m_player.SetPlayerState(PlayerState.Standing);
            //m_ledgeGrabBox.collider.enabled = true;
        }
    }
    public void OnFixedUpdate(ref GruntState playerState, ref int movingDirection, CGruntPhysics physics, FootMaterial footMaterial, bool isDetected)
    {
        if (playerState == GruntState.Walking)
        {
            if (isDetected)
            {
                m_currentAnimation = "run";
                if (!m_animation.IsPlaying("run"))
                {
                    m_animation.CrossFade("run", 0.2f);
                    PlayFootstepAudio(footMaterial);
                }
            }
            else
            {
                m_currentAnimation = "walk";
                if (!m_animation.IsPlaying("walk"))
                {
                    m_animation.CrossFade("walk", 0.2f);
                    PlayFootstepAudio(footMaterial);
                }
            }
        }
        else if (playerState == GruntState.Turning)
        {
            m_currentAnimation = "walk180turn";
            if (!m_animation.IsPlaying("walk180turn") && !m_startedTurningRound)
            {
                Debug.Log("On turn start");
                m_startedTurningRound            = true;
                m_animation["walk180turn"].speed = 1.0f;
                m_animation.CrossFade("walk180turn");
            }
            else if (!m_animation.IsPlaying("walk180turn"))
            {
                m_startedTurningRound = false;
                playerState           = GruntState.Walking;
                Debug.Log("On turn complete");

                /*
                 * if( movingDirection == 1)
                 * {
                 *      movingDirection = -1;
                 * }
                 * else if( movingDirection == -1 )
                 * {
                 *      movingDirection = 1;
                 * }
                 */
            }
        }
        else if (playerState == GruntState.Attacking)
        {
            m_currentAnimation = "alert_attack1";
            if (!m_animation.IsPlaying("alert_attack1") && !m_startedAttacking)
            {
                Debug.Log("On attack start");
                m_startedAttacking = true;
                m_animation["alert_attack1"].speed = 1.0f;
                m_animation.CrossFade("alert_attack1");
                PlayAttackSound();
            }
            else if (!m_animation.IsPlaying("alert_attack1"))
            {
                m_startedAttacking = false;
                playerState        = GruntState.Walking;
                Debug.Log("On attack complete");
            }
        }
        else if (playerState == GruntState.Standing)
        {
            if (!m_animation.IsPlaying(m_lastKnownIdle))
            {
                if (isDetected)
                {
                    m_currentAnimation = "alert-idle-" + Random.Range(0, 1);
                    m_animation[m_currentAnimation].speed = 1.0f;
                }
                else
                {
                    m_currentAnimation = "idle-" + Random.Range(0, 2);
                    m_animation[m_currentAnimation].speed = Random.Range(10, 30) / 100.0f;
                }
                m_lastKnownIdle = m_currentAnimation;
                m_animation.CrossFade(m_currentAnimation);
            }
        }
        else if (playerState == GruntState.Jumping)
        {
            m_currentAnimation = "run-jump";
            if (!m_animation.IsPlaying("run-jump"))
            {
                m_animation.Play("run-jump");
            }
        }
        else if (playerState == GruntState.FallJumping)
        {
            m_currentAnimation = "falling";
            if (!m_animation.IsPlaying("falling"))
            {
                m_animation.CrossFade("falling");
            }
        }
        else if (playerState == GruntState.FallingFromTower)
        {
            m_currentAnimation = "falling";
            if (!m_animation.IsPlaying("falling"))
            {
                m_animation.CrossFade("falling");
            }
        }
    }
    public void PlayFootstepAudio(FootMaterial material)
    {
        AudioClip[] clips = FootstepsStone;
        switch(material)
        {
        case FootMaterial.Wood:
            clips = FootstepsWood;
            break;
        case FootMaterial.Metal:
            clips = FootstepsMetal;
            break;
        }

        PlayRandomAudio(clips, false);
    }
    /*
     * \brief Called whilst a collision is taking place
    */
    public void CallOnCollisionStay(Collision collision, ref GruntState playerState, ref float playerAlpha)
    {
        m_collisionState = CollisionState.None;

        foreach (ContactPoint contact in collision)
        {
            Debug.DrawRay(contact.point, contact.normal);
            //
            if (contact.otherCollider != null && contact.otherCollider.gameObject != null)
            {
                CSceneObjectPlatform platform = contact.otherCollider.gameObject.GetComponent<CSceneObjectPlatform>();
                if (platform != null && m_platform == null) {
                    m_platform = platform;
                    m_platform.resetDeltaA();
                }
            }

            //
            CSceneObject obj = null;
            if (contact.otherCollider)
            {
                obj = contact.otherCollider.gameObject.GetComponent<CSceneObject>();
                if (obj == null && contact.otherCollider.gameObject.transform.parent != null) {
                    GameObject parent = contact.otherCollider.gameObject.transform.parent.gameObject;
                    if (parent != null) {
                        obj = parent.GetComponent<CSceneObject>();
                    }
                }
            }

            // floor check
            else if (isNearly(contact.normal.y, 1.0f, 0.8f))
            {
                m_collisionState = CollisionState.OnFloor;
                if (!isNearly(contact.normal.y, 1.0f, 0.15f) && collision.contacts.Length == 1)
                {
                    m_velocity = (m_movingDirection * 0.15f);
                    m_velocityLockTimer = (Time.time * 1000.0f);
                }
                if(contact.otherCollider)
                {
                    // 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;
                }
            }
            // head check
            else if (isNearly(contact.normal.y, -1.0f, 0.1f))
            {
                m_collisionState = CollisionState.OnRoof;
            }
            // wall check
            else
            {
                if (isFacingCollision(m_movingDirection, m_body.transform.position, contact.point, playerAlpha)) {
                    m_collisionState = CollisionState.OnWall;
                    break;
                }
            }
        }

        if (m_collisionState == CollisionState.OnWall && m_jumpState == JumpState.Jumping && playerState != GruntState.WallJumpStart)
        {
            m_velocity = -(m_movingDirection * 0.15f);
        }

        if (m_collisionState == CollisionState.OnFloor && ((Time.time * 1000.0f) - m_jumpTimer > 200.0f))
        {
            m_jumpState = JumpState.Landed;

            if (m_grunt.GetGruntState() != GruntState.Turning) m_grunt.SetGruntState(GruntState.Standing);
        }
    }
/*
 * \brief Called whilst a collision is taking place
 */
    public void CallOnCollisionStay(Collision collision, ref PlayerState playerState, ref float playerAlpha)
    {
        m_collisionState = CollisionState.None;

        foreach (ContactPoint contact in collision)
        {
            Debug.DrawRay(contact.point, contact.normal);

            //
            if (contact.otherCollider != null && contact.otherCollider.gameObject != null)
            {
                CSceneObjectPlatform platform = contact.otherCollider.gameObject.GetComponent <CSceneObjectPlatform>();
                if (platform != null && m_platform == null)
                {
                    m_platform = platform;
                    m_platform.resetDeltaA();
                }
            }

            //
            CSceneObject obj = null;
            if (contact.otherCollider)
            {
                obj = contact.otherCollider.gameObject.GetComponent <CSceneObject>();
                if (obj == null && contact.otherCollider.gameObject.transform.parent != null)
                {
                    GameObject parent = contact.otherCollider.gameObject.transform.parent.gameObject;
                    if (parent != null)
                    {
                        obj = parent.GetComponent <CSceneObject>();
                    }
                }
            }

            if (contact.thisCollider != null && contact.thisCollider.gameObject != null && contact.thisCollider.gameObject.name == "Ledge_Grab_Detection" && (obj == null || obj.CanLedgeGrab))
            {
                if (CSceneObject.CheckLedgeGrab(collision))
                {
                    continue;
                }
            }

            if (contact.otherCollider != null && contact.otherCollider.gameObject != null && contact.otherCollider.gameObject.name == "Ledge_Grab_Detection" && (obj == null || obj.CanLedgeGrab))
            {
                if (CSceneObject.CheckLedgeGrab(collision))
                {
                    continue;
                }
            }

            // wall jumping
            if (obj != null && obj.CanWallJump == true && m_jumpState != JumpState.Landed && !isNearly(contact.normal.y, 1.0f, 0.2f) && !isNearly(contact.normal.y, -1.0f, 0.1f))
            {
                m_collisionState         = CollisionState.OnWall;
                playerState              = PlayerState.WallJumpStart;
                m_jumpTimer              = (Time.time * 1000.0f);
                m_body.constraints       = RigidbodyConstraints.FreezeAll;
                m_velocity               = 0.0f;
                m_wallJump.StartHangTime = Time.time * 1000.0f;
            }
            // floor check
            else if (isNearly(contact.normal.y, 1.0f, 0.8f))
            {
                m_collisionState = CollisionState.OnFloor;
                if (!isNearly(contact.normal.y, 1.0f, 0.15f) && collision.contacts.Length == 1)
                {
                    m_velocity          = (m_movingDirection * 0.15f);
                    m_velocityLockTimer = (Time.time * 1000.0f);
                }

                // 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;
                }
            }
            // head check
            else if (isNearly(contact.normal.y, -1.0f, 0.1f))
            {
                m_collisionState = CollisionState.OnRoof;
            }
            // wall check
            else
            {
                if (isFacingCollision(m_movingDirection, m_body.transform.position, contact.point, playerAlpha))
                {
                    m_collisionState = CollisionState.OnWall;
                    break;
                }
            }
        }

        if (m_collisionState == CollisionState.OnWall && m_jumpState == JumpState.Jumping && playerState != PlayerState.WallJumpStart)
        {
            m_velocity = -(m_movingDirection * 0.15f);
        }

        if (m_collisionState == CollisionState.OnFloor && ((Time.time * 1000.0f) - m_jumpTimer > 200.0f))
        {
            m_jumpState = JumpState.Landed;

            if (m_ladderClimb.State != LadderState.AtBase)
            {
                m_ladderClimb.State = LadderState.None;
            }
            else
            {
                playerState = PlayerState.UpALadder;
            }

            if (m_player.GetPlayerState() != PlayerState.Turning)
            {
                m_player.SetPlayerState(PlayerState.Standing);
            }
            //m_ledgeGrabBox.collider.enabled = true;
        }
    }
 public void OnFixedUpdate(ref GruntState playerState, ref int movingDirection, CGruntPhysics physics, FootMaterial footMaterial, bool isDetected)
 {
     if (playerState == GruntState.Walking)
     {
         if(isDetected)
         {
             m_currentAnimation = "run";
             if (!m_animation.IsPlaying("run"))
             {
                 m_animation.CrossFade("run", 0.2f);
                 PlayFootstepAudio(footMaterial);
             }
         }
         else
         {
             m_currentAnimation = "walk";
             if (!m_animation.IsPlaying("walk"))
             {
                 m_animation.CrossFade("walk", 0.2f);
                 PlayFootstepAudio(footMaterial);
             }
         }
     }
     else if (playerState == GruntState.Turning)
     {
         m_currentAnimation = "walk180turn";
         if (!m_animation.IsPlaying("walk180turn") && !m_startedTurningRound)
         {
             Debug.Log("On turn start");
             m_startedTurningRound = true;
             m_animation["walk180turn"].speed = 1.0f;
             m_animation.CrossFade("walk180turn");
         }
         else if (!m_animation.IsPlaying("walk180turn"))
         {
             m_startedTurningRound = false;
             playerState = GruntState.Walking;
             Debug.Log("On turn complete");
             /*
             if( movingDirection == 1)
             {
                 movingDirection = -1;
             }
             else if( movingDirection == -1 )
             {
                 movingDirection = 1;
             }
             */
         }
     }
     else if (playerState == GruntState.Attacking)
     {
         m_currentAnimation = "alert_attack1";
         if (!m_animation.IsPlaying("alert_attack1") && !m_startedAttacking)
         {
             Debug.Log("On attack start");
             m_startedAttacking = true;
             m_animation["alert_attack1"].speed = 1.0f;
             m_animation.CrossFade("alert_attack1");
             PlayAttackSound();
         }
         else if (!m_animation.IsPlaying("alert_attack1"))
         {
             m_startedAttacking = false;
             playerState = GruntState.Walking;
             Debug.Log("On attack complete");
         }
     }
     else if (playerState == GruntState.Standing)
     {
         if (!m_animation.IsPlaying(m_lastKnownIdle))
         {
             if( isDetected )
             {
                 m_currentAnimation = "alert-idle-" + Random.Range(0, 1);
                 m_animation[m_currentAnimation].speed = 1.0f;
             }
             else
             {
                 m_currentAnimation = "idle-" + Random.Range(0, 2);
                 m_animation[m_currentAnimation].speed = Random.Range(10, 30) / 100.0f;
             }
             m_lastKnownIdle = m_currentAnimation;
             m_animation.CrossFade(m_currentAnimation);
         }
     }
     else if (playerState == GruntState.Jumping)
     {
         m_currentAnimation = "run-jump";
         if (!m_animation.IsPlaying("run-jump"))
             m_animation.Play("run-jump");
     }
     else if (playerState == GruntState.FallJumping)
     {
         m_currentAnimation = "falling";
         if (!m_animation.IsPlaying("falling"))
             m_animation.CrossFade("falling");
     }
     else if (playerState == GruntState.FallingFromTower)
     {
         m_currentAnimation = "falling";
         if (!m_animation.IsPlaying("falling"))
             m_animation.CrossFade("falling");
     }
 }