Beispiel #1
0
 private void OnBobDetected()
 {
     m_vrCharCont.InvokeBobEvent();
     m_vrCharCont.InvokeBobbingStartEvent();
     m_moveForwardUp   = false;                                                                                                                          // update movement state & check again.
     m_moveForwardDown = false;
     m_bobState        = BobState.BOBBING;
     m_bobTimer        = 0.0f;
 }
Beispiel #2
0
 private void OnBobbingStopped()
 {
     if (m_bobState == BobState.BOBBING)
     {
         m_vrCharCont.InvokeBobbingEndEvent();
     }
     m_bobState        = BobState.STILL;                                 // if the timer exceeds this time,
     m_moveForwardUp   = false;                                          // it means both of the up & down
     m_moveForwardDown = false;                                          // conditions were not hit in that time,
     m_bobTimer        = 0.0f;                                           // therefore stop movement, proceed back to checking
 }
Beispiel #3
0
        private void Update()
        {
            if (!IsPlaying)
            {
                return;
            }
            _curActionCd -= Time.deltaTime;
            _curStealCd  -= Time.deltaTime;
            if (_curStealCd < 0 && CurrentState < BobState.Stunned && _linkRoutine == null)
            {
                SetState(BobState.MovingForSteal);
            }
            if (_curActionCd < 0 && CurrentState < BobState.MovingForSteal && _linkRoutine == null)
            {
                SetState((BobState)Random.Range(0, 2));
            }
            if (_curActionCd < 0 && CurrentState == BobState.Stealing)
            {
                CurrentState = BobState.MissionFailedSuccesfuly;
                BobAudio.Stop();
                GameManager.Instance.BobGameOver();
            }
            if (!Agent.enabled)
            {
                return;
            }

            if (_curActionCd < 0 && Agent.remainingDistance < 1)
            {
                if (CurrentState == BobState.MovingForSteal)
                {
                    var direction = TargetAisle.AisleTarget.position - Agent.transform.position;
                    Agent.transform.rotation = Quaternion.LookRotation(direction);
                    SetState(BobState.Stealing);
                }
                else
                {
                    SetState(BobState.Idling);
                }
            }

            if (Agent.isOnOffMeshLink)
            {
                if (_linkRoutine == null)
                {
                    _linkRoutine = StartCoroutine(NormalSpeed(Agent));
                }
            }
        }
Beispiel #4
0
        private void SetState(BobState newState)
        {
            if (CurrentState == newState)
            {
                return;
            }
            CurrentState = newState;
            switch (newState)
            {
            case BobState.Idling:
                Agent.enabled = false;
                BobAnim.SetFloat(BlendParam, 0);
                _curActionCd = IdlingTime;
                break;

            case BobState.Strolling:
                Agent.enabled = true;
                BobAnim.SetFloat(BlendParam, 1);
                Repath();
                _curActionCd = IdlingTime;
                break;

            case BobState.MovingForSteal:
                Agent.enabled = true;
                BobAnim.SetFloat(BlendParam, 1);
                _curActionCd = 1f;
                BobAudio.SendStealWarning();
                Repath(true);
                break;

            case BobState.Stealing:
                Agent.enabled = false;
                BobAnim.SetFloat(BlendParam, 2);
                _curActionCd = StealTime;
                BobAudio.StartStealing();
                break;

            case BobState.Stunned:
                Agent.enabled = false;
                BobAnim.SetFloat(BlendParam, 3);
                _curActionCd = StunTime;
                _curStealCd  = StealCD;
                BobAudio.Stop();
                break;

            default:
                break;
            }
        }
Beispiel #5
0
        /// <summary>
        /// Wrapper for the logic that will update head bob if it is enabled
        /// <para>Returns <c>true</c>  if you are bobbing, Returns <c>false</c> if you are not.</para>
        /// </summary>
        private bool TrackingHeadbob()
        {
            if (trackHeadBob == false)
            {
                m_bobState = BobState.STILL;
                return(false);
            }
            if (m_pressing)
            {
                return(true);
            }
            else
            {
                return(false);
            }


            return(true);
        }
    /// <summary>
    /// Handle simple AI follow behavior and bobbing movement
    /// </summary>
    private void FixedUpdate()
    {
        // Reset velocity
        velocity = Vector3.zero;

        // Increment currentBobDuration
        currentBobDuration++;

        // Move the shark vertically according to BobState
        if (bobState == BobState.Up)
        {
            absoluteVerticalVelocity = bobVelocity;
        }
        else if (bobState == BobState.Down)
        {
            absoluteVerticalVelocity = -bobVelocity;
        }

        // Check if we should change the bob state and reset the duration
        if (currentBobDuration >= bobDuration && bobState != BobState.Steady)
        {
            bobState           = (bobState == BobState.Up ? BobState.Down : BobState.Up);
            currentBobDuration = 0;
        }

        // Move the shark towards the player if player is within follow distance
        distanceFromPlayer = Vector3.Distance(this.transform.position, player.transform.position);
        if (distanceFromPlayer <= followDistance)
        {
            // Try to only rotate around the Y axis (I used this as a reference: http://forum.unity3d.com/threads/lookat-to-rotate-only-on-y-axis.49471/)
            targetPosition.x = player.transform.position.x;
            targetPosition.y = this.transform.position.y;
            targetPosition.z = player.transform.position.z;
            this.transform.LookAt(targetPosition);

            // A bit of a hack to reset the model to the rotation I want it at
            this.transform.Rotate(0, rotateOffsetY, originalRotationZ);

            // Also a hack to make the model move "forward"
            velocity.x = -forwardVelocity;
        }

        // Get velocity based on how the shark is rotated
        localVelocity = this.transform.TransformDirection(velocity);

        // Make sure we apply a direct Y velocity for bobbing
        localVelocity.y = absoluteVerticalVelocity;

        // Hack for correcting Y values when they get messed up during collisions (usually only when player's rb moves the shark's rb)
        if (rb.position.y > maxPosY)
        {
            correctedPosition.x     = this.transform.position.x;
            correctedPosition.y     = maxPosY;
            correctedPosition.z     = this.transform.position.z;
            this.transform.position = correctedPosition;
            localVelocity.y         = 0;
        }
        else if (rb.position.y < minPosY)
        {
            correctedPosition.x     = this.transform.position.x;
            correctedPosition.y     = minPosY;
            correctedPosition.z     = this.transform.position.z;
            this.transform.position = correctedPosition;
            localVelocity.y         = 0;
        }

        // Apply final velocity calculations
        rb.velocity = localVelocity;
    }
Beispiel #7
0
        void Update()
        {
            if (!disableButton)
            {
                if (!isToggle)
                {
                    if (m_leftController.GetButtonDown((Valve.VR.EVRButtonId)buttonToPress))
                    {
                        m_pressing         = true;
                        m_activeController = m_leftController;
                    }
                    else if (m_rightController.GetButtonDown((Valve.VR.EVRButtonId)buttonToPress))
                    {
                        m_pressing         = true;
                        m_activeController = m_rightController;
                    }

                    if (m_pressing == true && (m_activeController.GetButtonUp((Valve.VR.EVRButtonId)buttonToPress)))
                    {
                        m_pressing         = false;
                        m_activeController = null;
                        Debug.Log("Stop Tracking");
                        m_agent.velocity = Vector3.zero;
#if UNITY_5_6
                        m_agent.isStopped = true;
#else
                        m_agent.Stop();
#endif
                        m_bobState = BobState.STILL;
                    }
                }
                else
                {
                    if (m_leftController.GetButtonDown((Valve.VR.EVRButtonId)buttonToPress) ||
                        m_rightController.GetButtonDown((Valve.VR.EVRButtonId)buttonToPress))
                    {
                        m_toggleOn = !m_toggleOn;
                    }
                }
            }
            else
            {
                m_pressing         = true;
                m_activeController = m_leftController;
            }

            if (isToggle)
            {
                if (m_toggleOn)
                {
                    m_pressing         = true;
                    m_activeController = m_leftController;
                }
                else
                {
                    m_pressing         = false;
                    m_activeController = null;
                    m_agent.velocity   = Vector3.zero;
#if UNITY_5_6
                    m_agent.isStopped = true;
#else
                    m_agent.Stop();
#endif
                    m_bobState = BobState.STILL;
                }
            }

            if (TrackingHeadbob())
            {
                CheckForHeadBob();
            }

            UpdateBobStates();
        }
Beispiel #8
0
    /// <summary>
    /// Handle simple AI patrol behavior and bobbing movement
    /// </summary>
    private void FixedUpdate()
    {
        // Reset velocity
        velocity = Vector3.zero;

        // Increment currentBobDuration
        currentBobDuration++;

        // Move the shark vertically according to BobState
        if (bobState == BobState.Up)
        {
            absoluteVerticalVelocity = bobVelocity;
        }
        else if (bobState == BobState.Down)
        {
            absoluteVerticalVelocity = -bobVelocity;
        }

        // Check if we should change the bob state and reset the duration
        if (currentBobDuration >= bobDuration && bobState != BobState.Steady)
        {
            bobState           = (bobState == BobState.Up ? BobState.Down : BobState.Up);
            currentBobDuration = 0;
        }

        // Look at current patrol position
        // Note: Is there a better way to set this without setting it equal to "new Vector3(float, float, float)"?  I don't want to create and destroy during updates if possible
        targetPosition.x = patrolPositions[currentPatrolIndex].x;
        targetPosition.y = this.transform.position.y;
        targetPosition.z = patrolPositions[currentPatrolIndex].z;
        this.transform.LookAt(targetPosition);

        // A bit of a hack to reset the model to the rotation I want it at
        this.transform.Rotate(0, rotateOffsetY, originalRotationZ);

        // If we reached our patrol position, set the patrol index to the next position
        if (Mathf.Abs(this.transform.position.x - patrolPositions[currentPatrolIndex].x) < 0.05f && Mathf.Abs(this.transform.position.z - patrolPositions[currentPatrolIndex].z) < 0.05f)
        {
            // Get new patrol index
            currentPatrolIndex = (currentPatrolIndex + 1) % patrolPositions.Length;
        }
        // otherwise, just move forward
        else
        {
            velocity.x = -forwardVelocity;
        }

        // Get velocity based on how the shark is rotated
        localVelocity = this.transform.TransformDirection(velocity);

        // Make sure we apply a direct Y velocity for bobbing
        localVelocity.y = absoluteVerticalVelocity;

        // Hack for correcting Y values when they get messed up during collisions (usually only when player's rb moves the shark's rb)
        if (rb.position.y > maxPosY)
        {
            correctedPosition.x     = this.transform.position.x;
            correctedPosition.y     = maxPosY;
            correctedPosition.z     = this.transform.position.z;
            this.transform.position = correctedPosition;
            localVelocity.y         = 0;
        }
        else if (rb.position.y < minPosY)
        {
            correctedPosition.x     = this.transform.position.x;
            correctedPosition.y     = minPosY;
            correctedPosition.z     = this.transform.position.z;
            this.transform.position = correctedPosition;
            localVelocity.y         = 0;
        }

        // Apply final velocity calculations
        rb.velocity = localVelocity;
    }