Beispiel #1
0
    /*
     * \brief Called once per frame
     */
    public override void FixedUpdate()
    {
        m_lastPlayerPositionAlpha = m_playerPositionAlpha;

        m_physics.OnFixedUpdate(ref m_playerState);

        m_playerPositionAlpha -= m_physics.Velocity;

        float additionalY = 0.0f;

        if (m_playerState == PlayerState.LedgeClimbComplete)
        {
            m_playerPositionAlpha    -= m_physics.MovingDirection * 4;
            m_lastPlayerPositionAlpha = m_playerPositionAlpha;
            additionalY          += 0.6f;
            rigidbody.constraints = RigidbodyConstraints.FreezeRotationX | RigidbodyConstraints.FreezeRotationZ;
            m_playerState         = PlayerState.Standing;
        }

        m_position = new Vector3(
            Mathf.Sin(m_playerPositionAlpha * Mathf.Deg2Rad) * PlayerPathRadius,
            transform.position.y + additionalY,
            Mathf.Cos(m_playerPositionAlpha * Mathf.Deg2Rad) * PlayerPathRadius
            );

        // Camera Positioning
        {
            float cameraAlpha = (m_playerPositionAlpha - m_cameraClass.CameraOffset) * Mathf.Deg2Rad;

            Vector3 camPostion = new Vector3(
                Mathf.Sin(cameraAlpha) * (m_cameraClass.DistanceFromPlayer + PlayerPathRadius),
                m_position.y,
                Mathf.Cos(cameraAlpha) * (m_cameraClass.DistanceFromPlayer + PlayerPathRadius)
                );

            m_cameraClass.SetPosition(camPostion);
            m_cameraClass.SetLookAt(transform.position);
        }

        // Animate and position the player model mesh
        {
            if (m_physics.Direction > 0)
            {
                this.transform.GetChild(0).transform.rotation = Quaternion.Euler(new Vector3(0, this.transform.rotation.eulerAngles.y + 90, 0));
            }
            else if (m_physics.Direction < 0)
            {
                this.transform.GetChild(0).transform.rotation = Quaternion.Euler(new Vector3(0, this.transform.rotation.eulerAngles.y - 90, 0));
            }

            m_animation.OnFixedUpdate(ref m_playerState);
        }

        base.FixedUpdate();
    }
Beispiel #2
0
    /*
     * \brief Called once per frame
     */
    public override void FixedUpdate()
    {
        m_lastPlayerPositionAlpha = m_playerPositionAlpha;

        m_physics.OnFixedUpdate(ref m_playerState);

        m_playerPositionAlpha -= m_physics.Velocity;
        m_playerPositionAlpha += m_physics.PlatformVelocity;        // * 1500;
        // reset platformVelocity
        m_physics.PlatformVelocity = 0.0f;

        float additionalY = 0.0f;

        if (m_playerState == PlayerState.LedgeClimbComplete)
        {
            m_playerPositionAlpha    -= m_physics.MovingDirection * 4;
            m_lastPlayerPositionAlpha = m_playerPositionAlpha;
            rigidbody.constraints     = RigidbodyConstraints.FreezeRotationX | RigidbodyConstraints.FreezeRotationZ;
            m_playerState             = PlayerState.Standing;

            CapsuleCollider capCollider = this.GetComponentInChildren <CapsuleCollider>();
            capCollider.enabled = true;

            //new stuffs
            Vector3 newPelvisOffset = this.transform.Find("Player_Mesh/Bip001/Bip001 Pelvis").position - this.transform.position;
            this.transform.position = this.transform.position + (newPelvisOffset - m_pelvisOffset) /*+ new Vector3(0, 0.09f, 0)*/;
        }

        if (m_playerState == PlayerState.FallingFromTower)
        {
            m_additionalRadius   += (0.025f * m_physics.Invert);
            m_additionalRadius    = Mathf.Clamp(m_additionalRadius, -3.0f, 3.0f);
            m_playerPositionAlpha = m_lastPlayerPositionAlpha;
        }

        float yPosition = transform.position.y + additionalY;

        if (m_dead.didDie)
        {
            yPosition     = m_lastCheckpoint.transform.position.y;
            m_dead.didDie = false;
        }

        if (m_playerState == PlayerState.OnLadder)
        {
            rigidbody.constraints = RigidbodyConstraints.FreezeAll;
            yPosition            += Physics.GetLadder.offset;
        }

        m_position = new Vector3(
            Mathf.Sin(m_playerPositionAlpha * Mathf.Deg2Rad) * (PlayerPathRadius + m_additionalRadius),
            yPosition,
            Mathf.Cos(m_playerPositionAlpha * Mathf.Deg2Rad) * (PlayerPathRadius + m_additionalRadius)
            );

        // Animate and position the player model mesh
        {
            if (m_playerState == PlayerState.Turning)
            {
                // do nothing on turn around
            }
            else if (m_playerState == PlayerState.OnLadder)
            {
                float spin = Physics.InsideTower ? -180.0f : 0.0f;
                m_characterMesh.rotation = Quaternion.Euler(new Vector3(0, this.transform.rotation.eulerAngles.y + spin, 0));
            }
            else
            {
                if (m_physics.Direction > 0)
                {
                    m_characterMesh.rotation     = Quaternion.Euler(new Vector3(0, this.transform.rotation.eulerAngles.y + 90, 0));
                    m_ledgeGrabBox.localPosition = new Vector3(0.18f, m_ledgeGrabBox.localPosition.y, m_ledgeGrabBox.localPosition.z);
                }
                else if (m_physics.Direction < 0)
                {
                    m_characterMesh.rotation     = Quaternion.Euler(new Vector3(0, this.transform.rotation.eulerAngles.y - 90, 0));
                    m_ledgeGrabBox.localPosition = new Vector3(-0.18f, m_ledgeGrabBox.localPosition.y, m_ledgeGrabBox.localPosition.z);
                }
                else if (m_physics.MovingDirection > 0)
                {
                    m_characterMesh.rotation     = Quaternion.Euler(new Vector3(0, this.transform.rotation.eulerAngles.y + 90, 0));
                    m_ledgeGrabBox.localPosition = new Vector3(0.18f, m_ledgeGrabBox.localPosition.y, m_ledgeGrabBox.localPosition.z);
                }
                else if (m_physics.MovingDirection < 0)
                {
                    m_characterMesh.rotation     = Quaternion.Euler(new Vector3(0, this.transform.rotation.eulerAngles.y - 90, 0));
                    m_ledgeGrabBox.localPosition = new Vector3(-0.18f, m_ledgeGrabBox.localPosition.y, m_ledgeGrabBox.localPosition.z);
                }
            }

            m_animation.OnFixedUpdate(ref m_playerState, this);
        }


        if (m_playerState == PlayerState.FallingFromTower && (Time.time * 1000.0f) - m_dead.time > 2000)
        {
            OnDeath();
        }

        //Not very nice - reenables collider if no longer ledge hanging/climbing
        if (
            m_playerState != PlayerState.LedgeHang &&
            m_playerState != PlayerState.LedgeClimb &&
            m_playerState != PlayerState.LedgeClimbComplete
            )
        {
            CapsuleCollider capCollider = this.GetComponentInChildren <CapsuleCollider>();
            capCollider.enabled = true;
        }

        base.FixedUpdate();
    }
    /*
     * \brief Called once per frame
     */
    public override void FixedUpdate()
    {
        m_lastPlayerPositionAlpha = m_playerPositionAlpha;

        m_physics.OnFixedUpdate(ref m_playerState);

        m_playerPositionAlpha -= m_physics.Velocity;
        m_playerPositionAlpha += m_physics.PlatformVelocity;        // * 1500;
        // reset platformVelocity
        m_physics.PlatformVelocity = 0.0f;

        float additionalY = 0.0f;

        if (m_playerState == PlayerState.LedgeClimbComplete)
        {
            m_playerPositionAlpha    -= m_physics.MovingDirection * 4;
            m_lastPlayerPositionAlpha = m_playerPositionAlpha;
            additionalY                    += 0.65f;
            rigidbody.constraints           = RigidbodyConstraints.FreezeRotationX | RigidbodyConstraints.FreezeRotationZ;
            m_playerState                   = PlayerState.Standing;
            m_physics.CurrentCollisionState = CollisionState.OnFloor;
            CapsuleCollider capCollider = this.GetComponentInChildren <CapsuleCollider>();
            capCollider.enabled = true;
        }

        if (m_physics.LadderClimb.State != LadderState.None)
        {
            additionalY += m_physics.LadderClimb.Offset;
        }

        if (m_playerState == PlayerState.FallingFromTower)
        {
            m_additionalRadius   += (0.025f * m_physics.Invert);
            m_additionalRadius    = Mathf.Clamp(m_additionalRadius, -3.0f, 3.0f);
            m_playerPositionAlpha = m_lastPlayerPositionAlpha;
        }

        float yPosition = transform.position.y + additionalY;

        if (m_dead.didDie)
        {
            yPosition     = m_lastCheckpoint.transform.position.y;
            m_dead.didDie = false;
        }

        m_position = new Vector3(
            Mathf.Sin(m_playerPositionAlpha * Mathf.Deg2Rad) * (PlayerPathRadius + m_additionalRadius),
            yPosition,
            Mathf.Cos(m_playerPositionAlpha * Mathf.Deg2Rad) * (PlayerPathRadius + m_additionalRadius)
            );

        // Camera Positioning
        {
            //m_cameraClass.TendToMaxOffset(m_physics.Direction);

            Vector3 camPostion = Vector3.zero;

            float timeStoodStill = (Time.time * 1000.0f) - m_standingStillTime;
            if ((m_playerState == PlayerState.Standing && (timeStoodStill > m_cameraClass.CameraZoomTimerMs)) && m_physics.IsOnPlatform() == false)
            {
                m_cameraClass.DistanceFromPlayer -= 0.01f;
            }
            else
            {
                m_cameraClass.DistanceFromPlayer += 0.1f;
            }

            m_cameraClass.DistanceFromPlayer = Mathf.Clamp(m_cameraClass.DistanceFromPlayer, m_cameraClass.MinimumCameraDistance, m_cameraClass.MaximumCameraDistance);
            float cameraDistance = m_cameraClass.DistanceFromPlayer * m_physics.Invert;

            if (m_playerState == PlayerState.UpALadder && m_physics.CollisionType == CollisionState.None)
            {
                camPostion = new Vector3(
                    0,
                    0,
                    cameraDistance
                    );
            }
            else
            {
                float movingDirection = Physics.MovingDirection;
                if (movingDirection == 0)
                {
                    // this is bad
                    movingDirection = 1;
                    if (m_characterMesh.rotation.eulerAngles.y > 180.0f)
                    {
                        movingDirection = -1;
                    }
                }

                if (m_playerState == PlayerState.Turning)
                {
                    movingDirection *= -1.0f;
                }

                camPostion = new Vector3(
                    (movingDirection == -1) ? -cameraDistance : cameraDistance,
                    0,
                    0
                    );
            }

            if (m_playerState == PlayerState.FallingFromTower)
            {
                camPostion.y = m_dead.y;
            }

            Vector3 lookatOffset = transform.FindChild("Player_Mesh/Bip001/Bip001 Pelvis").position;

            m_cameraClass.SetPosition(camPostion);
            m_cameraClass.SetLookAt(lookatOffset);
        }

        // Animate and position the player model mesh
        {
            if (m_playerState == PlayerState.UpALadder)
            {
                m_characterMesh.rotation = Quaternion.Euler(new Vector3(0, this.transform.rotation.eulerAngles.y - 180, 0));
            }
            else if (m_playerState == PlayerState.Turning)
            {
            }
            else
            {
                if (m_physics.Direction > 0)
                {
                    m_characterMesh.rotation = Quaternion.Euler(new Vector3(0, this.transform.rotation.eulerAngles.y + 90, 0));
                    //m_ledgeGrabBox.localPosition = new Vector3(0.18f, m_ledgeGrabBox.localPosition.y, m_ledgeGrabBox.localPosition.z);
                }
                else if (m_physics.Direction < 0)
                {
                    m_characterMesh.rotation = Quaternion.Euler(new Vector3(0, this.transform.rotation.eulerAngles.y - 90, 0));
                    //m_ledgeGrabBox.localPosition = new Vector3(-0.18f, m_ledgeGrabBox.localPosition.y, m_ledgeGrabBox.localPosition.z);
                }
                else if (m_physics.MovingDirection > 0)
                {
                    m_characterMesh.rotation = Quaternion.Euler(new Vector3(0, this.transform.rotation.eulerAngles.y + 90, 0));
                    //m_ledgeGrabBox.localPosition = new Vector3(0.18f, m_ledgeGrabBox.localPosition.y, m_ledgeGrabBox.localPosition.z);
                }
                else if (m_physics.MovingDirection < 0)
                {
                    m_characterMesh.rotation = Quaternion.Euler(new Vector3(0, this.transform.rotation.eulerAngles.y - 90, 0));
                    //m_ledgeGrabBox.localPosition = new Vector3(-0.18f, m_ledgeGrabBox.localPosition.y, m_ledgeGrabBox.localPosition.z);
                }
            }

            m_animation.OnFixedUpdate(ref m_playerState, m_physics.LadderClimb.State, m_physics.GetFootMaterial());
        }


        if (m_playerState == PlayerState.FallingFromTower && (Time.time * 1000.0f) - m_dead.time > 3000)
        {
            OnDeath();
        }

        //Not very nice - reenables collider if no longer ledge hanging/climbing
        if (
            m_playerState != PlayerState.LedgeHang &&
            m_playerState != PlayerState.LedgeClimb &&
            m_playerState != PlayerState.LedgeClimbComplete
            )
        {
            CapsuleCollider capCollider = this.GetComponentInChildren <CapsuleCollider>();
            capCollider.enabled = true;
        }

        base.FixedUpdate();
    }