Exemplo n.º 1
0
        public void MoveToSticky(Vector3 destination)
        {
            _destination = destination;
            if (_pollHandle != null)
            {
                _pollHandle.Stop();
            }

            GameServices.messageBus.Unsubscribe(this);
            GameServices.messageBus.Subscribe(this);

            _unit.MoveTo(destination, false);
        }
Exemplo n.º 2
0
        private void takeRandomAction(List <IGridCell> futureStates, List <int> futureDirections)
        {
            int randomAction = Random.Range(0, futureStates.Count);              //select random action

            float[] featureValues = getState(futureStates [randomAction].position, futureDirections[randomAction]);

            float Qvalue = getQvalue(featureValues);

            previousfeaturesVector = featureValues;

            prevQVal = Qvalue;

            _unit.MoveTo(futureStates[randomAction].position, false);
        }
Exemplo n.º 3
0
        private void MoveNext(bool append)
        {
            var unitMask = _unit.attributes;

            Vector3 pos        = Vector3.zero;
            bool    pointFound = false;
            int     attempts   = 0;

            while (!pointFound && attempts < this.bailAfterFailedAttempts)
            {
                pos = _startPos + (Random.insideUnitSphere * Random.Range(1.0f, this.radius)).AdjustAxis(0.0f, Axis.Y);

                var dir  = (pos - this.transform.position.AdjustAxis(0.0f, Axis.Y));
                var dist = dir.magnitude;
                if (dist < this.minimumDistance)
                {
                    pos = this.transform.position + ((dir / dist) * this.minimumDistance);
                }

                var grid = GridManager.instance.GetGrid(pos);
                if (grid != null)
                {
                    var cell = grid.GetCell(pos, true);
                    pointFound = cell.isWalkable(unitMask);
                }
                else
                {
                    pointFound = true;
                }

                attempts++;
            }

            _unit.MoveTo(pos, append);
        }
        public float?ExecuteUpdate(float deltaTime, float nextInterval)
        {
            // if there are no more enemies, disable this behaviour
            if (!IsValid())
            {
                Disable();
                return(null);
            }

            if (owner.tauntTarget != null)
            {
                target = owner.tauntTarget.transform;
            }
            else
            {
                // gets the closest target in the list.
                target = enemies[0].transform;
            }

            if (target != null && _unit != null)
            {
                // if there is a target, move the unit towards that target
                _unit.MoveTo(target.localPosition, false);
            }

            return(null);
        }
Exemplo n.º 5
0
        private void MoveNext(bool append)
        {
            var unitMask = _unit.attributes;

            Vector3 pos        = Vector3.zero;
            bool    pointFound = false;
            int     attempts   = 0;

            while (!pointFound && attempts < this.bailAfterFailedAttempts)
            {
                pos = _startPos + (Random.insideUnitSphere.OnlyXZ() * Random.Range(1.0f, this.radius));

                var dir = _unit.position.DirToXZ(pos);
                if (dir.sqrMagnitude < this.minimumDistance * this.minimumDistance)
                {
                    pos = _unit.position + (dir.normalized * this.minimumDistance);
                }

                var grid = GridManager.instance.GetGrid(pos);
                if (grid != null)
                {
                    var cell = grid.GetCell(pos, true);
                    pointFound = cell.isWalkable(unitMask);
                }
                else
                {
                    pointFound = true;
                }

                attempts++;
            }

            _unit.MoveTo(pos, append);
        }
Exemplo n.º 6
0
        public static ILoadBalancedHandle Follow(this IUnitFacade unit, Transform target, float minimalMoveDiff = 0.5f, float checkInterval = 0.1f)
        {
            Vector3 lastRecordedTargetPosition = target.position;

            unit.MoveTo(lastRecordedTargetPosition, false);

            return(LoadBalancer.defaultBalancer.Execute((ignored) =>
            {
                bool updateMoveOrder = (lastRecordedTargetPosition - target.position).sqrMagnitude > minimalMoveDiff;

                if (updateMoveOrder)
                {
                    lastRecordedTargetPosition = target.position;
                    unit.MoveTo(lastRecordedTargetPosition, false);
                }

                return true;
            },
                                                        checkInterval,
                                                        true));
        }
Exemplo n.º 7
0
        // Use this for initialization
        void Start()
        {
            IGrid mainGrid = GridManager.instance.GetGrid(new Vector3(0, 0, 0));

            _unit = this.GetUnitFacade();
            if (_unit == null)
            {
                Debug.LogError("WanderBehaviour requires a component that implements IMovable.");
                this.enabled = false;
            }

            Cell destination = mainGrid.GetCell(new Vector3(-10, 0, 10));


            _unit.MoveTo(destination.position, false);

            Debug.Log(destination.matrixPosX + " " + destination.matrixPosZ);
        }
        void IHandleMessage <UnitNavigationEventMessage> .Handle(UnitNavigationEventMessage message)
        {
            if (message.eventCode == UnitNavigationEventMessage.Event.StoppedDestinationBlocked)
            {
                var grid = GridManager.instance.GetGrid(message.destination);
                if (grid == null)
                {
                    return;
                }

                var cell = grid.GetNearestWalkableCell(message.destination, this.transform.position, false, scanRadius, _unit);
                if (cell != null)
                {
                    message.isHandled = true;

                    _unit.MoveTo(cell.position, false);
                }
            }
        }
Exemplo n.º 9
0
 protected override void OnStop()
 {
     unit.MoveTo(unit.position, false);
 }
Exemplo n.º 10
0
 protected override void OnStartAndEnable()
 {
     _lastRecordedTargetPosition = target.position;
     _unit.MoveTo(_lastRecordedTargetPosition, false);
 }