void FindNewPosition_Enter()
        {
            BotLocomotiveComponent.UnFocus();
            // RICHARD
            if (Time.time - _timeStampFindNewPosition < _spamTresholdFindNewPosition)
            {
                _spamCountFindNewPosition++;
                LogInDebugMode($"_spamCountFindNewPosition: {_spamCountFindNewPosition}");
                if (IsFindNewPositionOverSpamLimit())
                {
                    _wanderAutoRetry = false;
                    LogInDebugMode($"_spamCountFindNewPosition  > _findNewPositionSpamLimit: {_spamCountFindNewPosition} > {_spamLimitfindNewPosition}");
                    FSM.ChangeState(FStatesWander.CannotWander);
                    return;
                }
            }
            else
            {
                _spamCountFindNewPosition = 0;
                _timeStampFindNewPosition = Time.time;
                LogInDebugMode($"_timeStampFindNewPosition: {_timeStampFindNewPosition}");
            }

            _findPositionTimeout = GetWaitTime();
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Check if Bot has approximately reached destination
 /// </summary>
 public bool HasReachedDestinationApprox(Bot.DistanceType StopMovementCondition)
 {
     return(BotLocomotiveComponent.StopMovementCondition == StopMovementCondition &&
            BotLocomotiveComponent.IsWithinDistance(StopMovementCondition, ProximityHelpers.DistanceDirection.VERTICAL) &&
            BotLocomotiveComponent.IsWithinDistance(StopMovementCondition, ProximityHelpers.DistanceDirection.HORIZONTAL)
            );
 }
 /// <summary>
 /// Move away from FocusedOnPosition
 /// </summary>
 public override void MoveAway(bool fullspeed = true)
 {
     RotateAwayFromPosition();
     if (!BotLocomotiveComponent.IsAway())
     {
         Flying3DObjectComponent.ApplyForwardThrust(fullspeed ? 1f : 0.2f);
     }
 }
 void OnCollisionEnter(Collision collision)
 {
     if (FSM.CurrentState == FStatesWander.MovingToPosition &&
         !CollisionWhiteListTags.Contains(collision.transform.tag))
     {
         BotLocomotiveComponent.FocusOnPosition(collision.GetContact(0).point);
         BotLocomotiveComponent.MoveAwayFromPosition(false);
     }
 }
        public void MoveToClosestEdge(bool fullspeed = true)
        {
            NavMeshHit hit;

            NavMeshAgentComponent.FindClosestEdge(out hit);
            BotLocomotiveComponent.UnFocus();
            BotLocomotiveComponent.FocusOnPosition(hit.position);
            MoveTowardsPosition(fullspeed);
            // BotLocomotiveComponent.MoveToPosition(BotLocomotive.StopMovementConditions.WITHIN_PERSONAL_SPACE, fullspeed);
            BotLocomotiveComponent.MoveToPosition(Bot.DistanceType.PERSONAL_SPACE, fullspeed);
        }
        public bool StopWandering(bool stopMoving = false)
        {
            if (FSM.CurrentState != FStatesWander.NotWandering)
            {
                if (stopMoving)
                {
                    BotLocomotiveComponent.StopMoving();
                }
                FSM.ChangeState(FStatesWander.NotWandering);
                return(true);
            }

            return(false);
        }
        public Vector3?JumpOffLedge(bool fullspeed = false)
        {
            RaycastHit rayhit;

            if (CanJumpDown(out rayhit))
            {
                BotLocomotiveComponent.UnFocus();
                BotLocomotiveComponent.FocusOnPosition(rayhit.point);
                // BotLocomotiveComponent.MoveToPosition(BotLocomotive.StopMovementConditions.AT_POSITION, fullspeed);
                BotLocomotiveComponent.MoveToPosition(Bot.DistanceType.AT_POSITION, fullspeed);
                return(rayhit.point);
            }
            return(null);
        }
 void MovingToPosition_Enter()
 {
     if (_currentBotWanderComponent.MovementTimeout > 0)
     {
         _movingToPosition_TimeOut = MovingToPosition_TimeOut();
         if (!BotLocomotiveComponent.MoveToPosition(_currentBotWanderComponent.StopMovementCondition, false))
         {
             FSM.ChangeState(FStatesWander.CannotWander);
             return;
         }
         DebugHelpers.LogInDebugMode(DebugMode, DEBUG_TAG, $"{transform.name} Wandering to {BotLocomotiveComponent.FocusedOnPosition.ToString()}");
         StartCoroutine(_movingToPosition_TimeOut);
     }
 }
 public override bool MoveTowardsPosition(bool fullspeed = true)
 {
     if (BotLocomotiveComponent.CurrentFState == BotLocomotive.FStatesLocomotion.MovingToPosition &&
         BotLocomotiveComponent.IsWithinDistance(Bot.DistanceType.PERSONAL_SPACE))    // IsAtPosition())
     {
         return(false);
     }
     if (fullspeed)
     {
         MoveTo(BotLocomotiveComponent.FocusedOnPosition.Value, RunSpeed, RunRotationSpeed);
     }
     else
     {
         MoveTo(BotLocomotiveComponent.FocusedOnPosition.Value, WalkSpeed, WalkRotationSpeed);
     }
     return(true);
 }
        public override bool MoveTowardsPosition(bool fullspeed = true)
        {
            RotateTowardsPosition();

            // Match height of position
            if (BotLocomotiveComponent.FocusedOnPosition.Value.y - BotLocomotiveComponent.transform.position.y >= (BotLocomotiveComponent.SqrAtPositionErrorMargin / 2))
            {
                Flying3DObjectComponent.ApplyVerticalThrust(true);
            }

            if (BotLocomotiveComponent.FocusedOnPosition.Value.y - BotLocomotiveComponent.transform.position.y < -(BotLocomotiveComponent.SqrAtPositionErrorMargin / 2))
            {
                Flying3DObjectComponent.ApplyVerticalThrust(false);
            }

            if (BotLocomotiveComponent.IsWithinDistance(Bot.DistanceType.AT_POSITION, ProximityHelpers.DistanceDirection.ALL))
            {
                // At position, stop all forces
                Flying3DObjectComponent.ResetAppliedForces();
                Flying3DObjectComponent.RigidBodyComponent.ResetInertiaTensor();
                // Flying3DObjectComponent.ResetAppliedAxis();
                return(false);
            }
            else if (BotLocomotiveComponent.IsWithinDistance(Bot.DistanceType.PERSONAL_SPACE, ProximityHelpers.DistanceDirection.ALL, 0.85f))       // .IsWithinPersonalSpace(0.85f))
            {
                Flying3DObjectComponent.ApplyForwardThrust(fullspeed ? 0.1f : 0.05f);                                                               //-0.35f : 0.05f);
            }
            else if (BotLocomotiveComponent.IsWithinDistance(Bot.DistanceType.PERSONAL_SPACE, ProximityHelpers.DistanceDirection.HORIZONTAL, 1.1f)) // IsWithinPersonalSpace(1.1f))
            {
                Flying3DObjectComponent.ApplyForwardThrust(fullspeed ? 0.25f : 0.05f);
            }
            else if (BotLocomotiveComponent.IsWithinDistance(Bot.DistanceType.INTERACTION, ProximityHelpers.DistanceDirection.HORIZONTAL)) // IsWithinInteractionDistance())
            {
                // Slow down
                Flying3DObjectComponent.ApplyForwardThrust(fullspeed ? 0.5f : 0.15f);
            }
            // Move towards position
            else // if (!BotLocomotiveComponent.IsWithinInteractionDistance())
            {
                Flying3DObjectComponent.ApplyForwardThrust(fullspeed ? 1f : 0.2f);
            }

            return(true);
        }
Ejemplo n.º 11
0
        private BehaviourAction.ActionResult DoPatrol(bool cancel)
        {
            if (cancel)
            {
                return(BehaviourAction.ActionResult.FAILED);
            }
            if (IsTargetWithinSight())
            {
                TargetTransforms = _botVisionComponent.DoLookoutFor(false, false, TargetTag);
                return(BehaviourAction.ActionResult.SUCCESS);
            }

            if (BotLocomotiveComponent.HasReachedDestination())
            {
                MoveToNextWaypoint();
            }

            return(BehaviourAction.ActionResult.PROGRESS);
        }
        public override void MoveAway(bool fullspeed = true)
        {
            var destination = BotLocomotiveComponent.GetMoveAwayDestination();

            NavMeshHit _hit;

            if (NavMesh.SamplePosition(destination, out _hit, BotLocomotiveComponent.SqrAwarenessMagnitude, -1))
            {
                destination = _hit.position;
            }

            if (fullspeed)
            {
                MoveTo(destination, RunSpeed, RunRotationSpeed);
            }
            else
            {
                MoveTo(destination, WalkSpeed, WalkRotationSpeed);
            }
        }
        void FindNewPosition_Update()
        {
            _findPositionTimeout -= Time.deltaTime;
            if (_findPositionTimeout > 0)
            {
                return;
            }

            _newWanderPosition = _currentBotWanderComponent.GetNewWanderPosition(WanderCenter);

            if (_newWanderPosition != null)
            {
                BotLocomotiveComponent.FocusOnPosition(_newWanderPosition.Value);
                FSM.ChangeState(FStatesWander.MovingToPosition);
            }
            else
            {
                LogInDebugMode("_newWanderPosition != null");
                _wanderAutoRetry = false;
                FSM.ChangeState(FStatesWander.CannotWander);
            }
        }
Ejemplo n.º 14
0
 private void MoveToWaypoint()
 {
     BotLocomotiveComponent.FocusOnTransform(_waypoints[_waypointIndex]);
     // BotLocomotiveComponent.MoveToTarget(BotLocomotive.StopMovementConditions.WITHIN_PERSONAL_SPACE, false);
     BotLocomotiveComponent.MoveToTarget(Bot.DistanceType.PERSONAL_SPACE, false);
 }
        public override void RotateAwayFromPosition()
        {
            var rotation = Quaternion.LookRotation(BotLocomotiveComponent.GetMoveAwayDestination() - BotLocomotiveComponent.transform.position, Vector3.up);

            BotLocomotiveComponent.transform.rotation = Quaternion.RotateTowards(BotLocomotiveComponent.transform.rotation, rotation, NavMeshAgentComponent.angularSpeed * Time.deltaTime);
        }
Ejemplo n.º 16
0
 /// <summary>
 /// Check if Bot has reached destination
 /// </summary>
 public bool HasReachedDestination(Bot.DistanceType StopMovementCondition)
 {
     return(BotLocomotiveComponent.StopMovementCondition == StopMovementCondition &&
            BotLocomotiveComponent.IsWithinDistance(StopMovementCondition));
 }
        public override void RotateAwayFromPosition()
        {
            var rotation = Quaternion.LookRotation(BotLocomotiveComponent.GetMoveAwayDestination() - BotLocomotiveComponent.transform.position, Vector3.up);

            Flying3DObjectComponent.YawTo(rotation.eulerAngles.y);
        }