public override void Update()
    {
        float targetVSpeed = 0;
        float velocity     = ParentCharacter.GetCharacterVelocity().magnitude;

        if (this.ParentCharacter.CurrentStance == HumanStances.Run)
        {
            targetVSpeed = 1.5f * ParentCharacter.MyStatus.RunSpeedModifier;
            ParentCharacter.Stealth.SetNoiseLevel(10, 0.6f);
        }
        else if (this.ParentCharacter.CurrentStance == HumanStances.Walk)
        {
            targetVSpeed = 0.5f * ParentCharacter.MyStatus.WalkSpeedModifier;


            ParentCharacter.Stealth.SetNoiseLevel(8, 0.6f);
        }


        _vSpeed = Mathf.Lerp(_vSpeed, targetVSpeed, 6 * Time.deltaTime);
        //Debug.Log("VSpeed " + _vSpeed + " target speed " + targetVSpeed);
        this.ParentCharacter.MyAnimator.SetFloat("VSpeed", _vSpeed);

        HandleNavAgentMovement();
    }
    public override void Update()
    {
        float targetVSpeed = 0;
        float velocity     = ParentCharacter.GetCharacterVelocity().magnitude;

        if (velocity > 0 && velocity <= 1.5f)       //(this.ParentCharacter.CurrentStance == HumanStances.Crouch)
        {
            targetVSpeed = 0.9f;
        }
        else if (velocity > 1.5f)       //(this.ParentCharacter.CurrentStance == HumanStances.CrouchRun)
        {
            targetVSpeed = 1.3f;
        }

        _vSpeed = Mathf.Lerp(_vSpeed, targetVSpeed, 6 * Time.deltaTime);
        //Debug.Log("VSpeed " + _vSpeed);
        this.ParentCharacter.MyAnimator.SetFloat("VSpeed", _vSpeed);


        if (ParentCharacter.MyNavAgent != null)
        {
            HandleNavAgentMovement();
        }


        HandleTurnMovement();
    }
    public void UpdateAction()
    {
        if (!CheckAvailability() || _executionStopped)
        {
            return;
        }

        if (ParentCharacter.MyAI.BlackBoard.TargetCorpse != null)
        {
            Vector3 distance = ParentCharacter.MyAI.BlackBoard.TargetCorpse.LastKnownPos - ParentCharacter.transform.position;
            if (distance.magnitude > 2)
            {
                ParentCharacter.CurrentStance = HumanStances.Run;
                ParentCharacter.MyAI.TargetingSystem.SetTargetingMode(AITargetingModes.LookAhead, Vector3.zero);
                Vector3 dest = ParentCharacter.MyAI.BlackBoard.TargetCorpse.LastKnownPos - distance.normalized * 0.5f;
                ParentCharacter.Destination = dest;
                ParentCharacter.SendCommand(CharacterCommands.GoToPosition);
            }
            else
            {
                if (ParentCharacter.MyAI.IsCharacterFriendly((Character)ParentCharacter.MyAI.BlackBoard.TargetCorpse.Target))
                {
                    //if corpse and I are friendly, then I'll check corpse and then raise alert
                    if (ParentCharacter.GetCharacterVelocity().magnitude <= 0.1f)
                    {
                        ParentCharacter.MyAnimator.SetBool("IsChecking", true);
                    }

                    _checkTimer++;

                    if (_checkTimer > 3)
                    {
                        //notify everyone on the team to draw weapon and do random patrol
                        ParentCharacter.MyAI.Bark("Somebody killed him! Search perimeter!");
                        ParentCharacter.MyAI.BlackBoard.GuardLevel = 3;
                        ParentCharacter.SendDelayCallBack(2, ParentCharacter.MyAI.Squad.SetSquadAlertLevel, 3);
                        ParentCharacter.MyAI.Squad.BroadcastMemoryFact(ParentCharacter.MyAI.BlackBoard.TargetCorpse);
                        StopAction();

                        ParentCharacter.MyEventHandler.TriggerOnActionCompletion();
                        return;
                    }
                }
                else
                {
                    //not in same faction, will consider it as a container to loot
                }
            }
        }



        if (CheckActionCompletion())
        {
            StopAction();

            ParentCharacter.MyEventHandler.TriggerOnActionCompletion();
        }
    }
    public override void Update()
    {
        float targetVSpeed = 0;
        float velocity     = ParentCharacter.GetCharacterVelocity().magnitude;


        if (/*(velocity > this.ParentCharacter.MyStatus.WalkSpeed && velocity <= this.ParentCharacter.MyStatus.RunSpeed) &&*/ this.ParentCharacter.CurrentStance == HumanStances.Run)
        {
            if (this.ParentCharacter.UpperBodyState == HumanUpperBodyStates.Aim && !this.ParentCharacter.IsHipAiming)
            {
                targetVSpeed = 1f * this.ParentCharacter.MyStatus.StrafeSpeedModifier;
                ParentCharacter.Stealth.SetNoiseLevel(8, 0.6f);
            }
            else if (this.ParentCharacter.ActionState == HumanActionStates.Melee)
            {
                targetVSpeed = 0.5f;
                ParentCharacter.Stealth.SetNoiseLevel(8, 0.6f);
            }
            else
            {
                targetVSpeed = 1.5f * this.ParentCharacter.MyStatus.RunSpeedModifier;
                ParentCharacter.Stealth.SetNoiseLevel(10, 0.6f);
            }
        }
        else if (/*(velocity > 0 && velocity <= this.ParentCharacter.MyStatus.WalkSpeed) &&*/ this.ParentCharacter.CurrentStance == HumanStances.Walk)
        {
            targetVSpeed = 1;
            ParentCharacter.Stealth.SetNoiseLevel(8, 0.6f);
        }
        else if (/*(velocity > this.ParentCharacter.MyStatus.RunSpeed) &&*/ this.ParentCharacter.CurrentStance == HumanStances.Sprint)
        {
            targetVSpeed = 2f * this.ParentCharacter.MyStatus.SprintSpeedModifier;
            ParentCharacter.Stealth.SetNoiseLevel(15, 0.6f);
        }


        _vSpeed = Mathf.Lerp(_vSpeed, targetVSpeed, 8 * Time.deltaTime);
        if (velocity < 0.05f)
        {
            _vSpeed = 0;
        }
        //Debug.Log("VSpeed " + _vSpeed + " target speed " + targetVSpeed);
        this.ParentCharacter.MyAnimator.SetFloat("VSpeed", _vSpeed);

        if (ParentCharacter.MyNavAgent != null)
        {
            HandleNavAgentMovement();
        }
    }
示例#5
0
    public void PerFrameUpdate()
    {
        float dist = Vector3.Distance(ParentCharacter.transform.position, ParentCharacter.MyAI.BlackBoard.FollowTarget.transform.position);

        if (dist > _distThreshold)
        {
            Transform followTarget = ParentCharacter.MyAI.BlackBoard.FollowTarget.transform;
            ParentCharacter.Destination = followTarget.position + _followTargetPadding;
            ParentCharacter.MyAI.BlackBoard.NavTarget = ParentCharacter.Destination.Value;
        }
        else if (dist < _distThreshold / 2 && ParentCharacter.GetCharacterVelocity().magnitude > 0)
        {
            ParentCharacter.SendCommand(CharacterCommands.Idle);
        }
    }
    public override bool ExecuteAction()
    {
        Debug.Log("Start executing Hide in Cover ");
        Vector3 faceDir = ParentCharacter.GetCharacterVelocity().normalized * -1;

        ParentCharacter.MyAI.TargetingSystem.SetTargetingMode(AITargetingModes.LookAround, faceDir);


        ParentCharacter.SendCommand(CharacterCommands.Crouch);


        ParentCharacter.MyEventHandler.OnActionUpdateTimer -= UpdateAction;
        ParentCharacter.MyEventHandler.OnActionUpdateTimer += UpdateAction;

        UpdateAction();



        return(true);
    }
示例#7
0
 private void HandlePatrolUpdate()
 {
     if (ParentCharacter.MyAI.BlackBoard.IsNavTargetSet)
     {
         CsDebug.Inst.CharLog(ParentCharacter, "Patrol area update action nav target is set. is patrolling " + _isPatrolling);
         //check if is near patrol destination; if so set isNavTargetSet to false
         if (Vector3.Distance(ParentCharacter.transform.position, ParentCharacter.MyAI.BlackBoard.NavTarget) <= 2)
         {
             ParentCharacter.MyAI.BlackBoard.IsNavTargetSet = false;
             _isPatrolling = false;
             _idleDuration = UnityEngine.Random.Range(5f, 20f);
             _idleTimer    = 0;
         }
         else if (!_isPatrolling)
         {
             ParentCharacter.Destination = ParentCharacter.MyAI.BlackBoard.NavTarget;
             ((HumanCharacter)ParentCharacter).CurrentStance = HumanStances.Walk;
             ParentCharacter.SendCommand(CharacterCommands.GoToPosition);
             if (ParentCharacter.GetCharacterVelocity().magnitude <= 0)
             {
                 ParentCharacter.MyAI.BlackBoard.IsNavTargetSet = false;
             }
             _isPatrolling = true;
         }
     }
     else
     {
         CsDebug.Inst.CharLog(ParentCharacter, "Patrol area update action nav target is not set");
         Vector3 result;
         ParentCharacter.MyAI.BlackBoard.IsNavTargetSet = SelectPatrolDestination(out result);
         if (ParentCharacter.MyAI.BlackBoard.IsNavTargetSet)
         {
             ParentCharacter.MyAI.BlackBoard.NavTarget = result;
             ParentCharacter.Destination   = ParentCharacter.MyAI.BlackBoard.NavTarget;
             ParentCharacter.CurrentStance = HumanStances.Walk;
             ParentCharacter.SendCommand(CharacterCommands.GoToPosition);
             _isPatrolling = true;
         }
     }
 }
示例#8
0
    public void UpdateAction()
    {
        if (!CheckAvailability())
        {
            return;
        }



        if (ParentCharacter.MyAI.BlackBoard.IsNavTargetSet)
        {
            CsDebug.Inst.CharLog(ParentCharacter, "Patrol area update action nav target is set. is patrolling " + _isPatrolling);
            //check if is near patrol destination; if so set isNavTargetSet to false
            if (Vector3.Distance(ParentCharacter.transform.position, ParentCharacter.MyAI.BlackBoard.NavTarget) <= 2)
            {
                ParentCharacter.MyAI.BlackBoard.IsNavTargetSet = false;
            }
            else if (!_isPatrolling)
            {
                ParentCharacter.Destination = ParentCharacter.MyAI.BlackBoard.NavTarget;
                ((HumanCharacter)ParentCharacter).CurrentStance = HumanStances.Walk;
                ParentCharacter.SendCommand(CharacterCommands.GoToPosition);
                if (ParentCharacter.GetCharacterVelocity().magnitude <= 0)
                {
                    ParentCharacter.MyAI.BlackBoard.IsNavTargetSet = false;
                }
                _isPatrolling = true;
            }
            else if (_isPatrolling)
            {
                if (ParentCharacter.CurrentAnimStateName == "Idle")
                {
                    ParentCharacter.Destination = ParentCharacter.MyAI.BlackBoard.NavTarget;
                    ((HumanCharacter)ParentCharacter).CurrentStance = HumanStances.Walk;
                    ParentCharacter.SendCommand(CharacterCommands.GoToPosition);
                }
            }
        }
        else
        {
            CsDebug.Inst.CharLog(ParentCharacter, "Patrol area update action nav target is not set");
            Vector3 result;
            ParentCharacter.MyAI.BlackBoard.IsNavTargetSet = SelectPatrolDestination(out result);
            if (ParentCharacter.MyAI.BlackBoard.IsNavTargetSet)
            {
                ParentCharacter.MyAI.BlackBoard.NavTarget = result;
                ParentCharacter.Destination = ParentCharacter.MyAI.BlackBoard.NavTarget;
                ((HumanCharacter)ParentCharacter).CurrentStance = HumanStances.Walk;
                ParentCharacter.SendCommand(CharacterCommands.GoToPosition);
                _isPatrolling = true;
            }
        }

        //check if need to pull out weapon
        ParentCharacter.SendCommand(CharacterCommands.SetAlert);

        /*
         * if(ParentCharacter.MyAI.BlackBoard.GuardLevel > 1 && ParentCharacter.MyReference.CurrentWeapon == null)
         * {
         *
         *
         *
         * }
         * else if(ParentCharacter.MyAI.BlackBoard.GuardLevel <= 1 && ParentCharacter.MyReference.CurrentWeapon != null)
         * {
         *      ParentCharacter.SendCommand(CharacterCommands.Unarm);
         * }
         */

        //check if need to aim
        if (ParentCharacter.MyAI.BlackBoard.GuardLevel > 2 && ParentCharacter.MyReference.CurrentWeapon != null)
        {
            ParentCharacter.SendCommand(CharacterCommands.Aim);
        }
        else
        {
            ParentCharacter.SendCommand(CharacterCommands.StopAim);
        }

        ParentCharacter.MyAI.TargetingSystem.SetTargetingMode(AITargetingModes.LookAheadAround, Vector3.zero);

        //check if patrol is complete
        if (CheckActionCompletion())
        {
            StopAction();
            ParentCharacter.MyEventHandler.TriggerOnActionCompletion();
        }
    }
示例#9
0
    public void UpdateAction()
    {
        if (!CheckAvailability())
        {
            return;
        }


        ParentCharacter.SendCommand(CharacterCommands.Aim);

        CsDebug.Inst.CharLog(ParentCharacter, "is search dest set? " + _isSearchDestSet);
        if (_isSearchDestSet)
        {
            if (Vector3.Distance(ParentCharacter.transform.position, _searchDest) > 1)
            {
                ParentCharacter.Destination = _searchDest;
                ParentCharacter.SendCommand(CharacterCommands.GoToPosition);
                CsDebug.Inst.CharLog(ParentCharacter, "Sent command to go to " + ParentCharacter.Destination);
                if (ParentCharacter.GetCharacterVelocity().magnitude <= 0)
                {
                    _isSearchDestSet = false;
                }
            }
            else
            {
                _isSearchDestSet = false;
                ParentCharacter.MyAI.BlackBoard.IsNavTargetSet = false;
            }
        }
        else
        {
            //search random locations
            Vector3 searchCenter = ParentCharacter.transform.position;
            Vector3 searchRange  = new Vector3(5, 5, 5);
            if (ParentCharacter.MyAI.BlackBoard.InvisibleEnemy != null)
            {
                if (_searchTimer < 10)
                {
                    searchCenter = ParentCharacter.MyAI.BlackBoard.InvisibleEnemy.transform.position;
                    searchRange += new Vector3(_searchTimer / 2, 0, _searchTimer / 2);
                }
                else
                {
                    searchCenter = ParentCharacter.MyAI.BlackBoard.PatrolLoc;
                    searchRange  = ParentCharacter.MyAI.BlackBoard.PatrolRange;
                }
            }

            ParentCharacter.MyAI.BlackBoard.IsNavTargetSet = SelectSearchDestination(searchCenter, new Vector3(5, 5, 5), out _searchDest);
            _isSearchDestSet = ParentCharacter.MyAI.BlackBoard.IsNavTargetSet;
            if (ParentCharacter.MyAI.BlackBoard.IsNavTargetSet)
            {
                ParentCharacter.MyAI.BlackBoard.NavTarget = _searchDest;
                ParentCharacter.Destination = ParentCharacter.MyAI.BlackBoard.NavTarget;
                ((HumanCharacter)ParentCharacter).CurrentStance = HumanStances.Walk;

                ParentCharacter.SendCommand(CharacterCommands.GoToPosition);
                //CsDebug.Inst.CharLog(ParentCharacter, "Sent command to go to " + ParentCharacter.Destination);
                ParentCharacter.MyAI.TargetingSystem.SetTargetingMode(AITargetingModes.LookAheadAround, Vector3.zero);
            }
        }

        if (_searchTimer >= _nextTalkTime)
        {
            ParentCharacter.PlayVocal(VocalType.Search);
            _nextTalkTime = _searchTimer + UnityEngine.Random.Range(5, 10);
        }


        _searchTimer++;

        //check if patrol is complete
        if (CheckActionCompletion())
        {
            StopAction();
            ParentCharacter.MyEventHandler.TriggerOnActionCompletion();
        }
    }