예제 #1
0
        public void Tick()
        {
            var guards  = GuardStorage.GetGuards();
            var players = PlayerStorage.GetPlayers();


            foreach (var player in players)
            {
                foreach (var guard in guards)
                {
                    if (CanSeeTarget(guard, player))
                    {
                        player.PlayerVisibleTimer += Time.deltaTime;
                    }
                    else
                    {
                        player.PlayerVisibleTimer -= Time.deltaTime;
                    }

                    player.PlayerVisibleTimer = Mathf.Clamp(player.PlayerVisibleTimer, 0, player.TimeToSpotPlayer);

                    float _visability = player.PlayerVisibleTimer / player.TimeToSpotPlayer;

                    guard.Color = Color.Lerp(Color.green, Color.red, _visability);

                    GuardStorage.UpdateItem(guard);
                }

                PlayerStorage.UpdateItem(player);
            }
        }
예제 #2
0
        public void Tick()
        {
            if (!PlayerStorage.ContainsItem(_modelGuid))
            {
                return;
            }
            var model = PlayerStorage.GetItem(_modelGuid);

            model.GridPosition = GridUtil.ConvertToGrid(model.Position);

            var visability = model.PlayerVisibleTimer / model.TimeToSpotPlayer;

            if (Mathf.Approximately(visability, 1f))
            {
                Debug.LogWarning("Player Spoted!!!");
                model.IsSpotted = true;
            }

            if (!model.IsSpotted)
            {
                if (InputModelStorage.IsClicked())
                {
                    //reset previous path data
                    model.TargetPosition     = model.Position;
                    model.GridTargetPosition = model.GridPosition;
                    model.CurrentNode        = 0;

                    //get new target
                    model.Path = PathfinderUtil.GetPath(model.GridPosition, InputModelStorage.PopTargetIndex());
                }

                //to do получить цель движения

                if (model.Path != null && model.Path.Count > 0)
                {
                    if (Vector3.Distance(model.TargetPosition, model.Position) > 0.2f)
                    {
                        float movementSpeed = 2f * Time.deltaTime;
                        float rotationSpeed = 270f * Time.deltaTime;

                        Vector3 forward        = model.TargetPosition - model.Position;
                        var     rotationTarget = Quaternion.LookRotation(forward);
                        model.Position = Vector3.MoveTowards(model.Position, model.TargetPosition, movementSpeed);
                        model.Rotation = Quaternion.RotateTowards(model.Rotation, rotationTarget, rotationSpeed);
                    }
                    else
                    {
                        if (model.CurrentNode < model.Path.Count)
                        {
                            var target = model.Path[model.CurrentNode];
                            model.TargetPosition = GridUtil.ConvertPointToPosition(target);
                            model.CurrentNode++;
                        }
                        else
                        {
                            model.CurrentNode = 0;
                            model.Path        = new List <Point>();
                        }
                    }
                }
            }

            PlayerStorage.UpdateItem(model);

            _playerView.SetRotation(model.Rotation);
            _playerView.SetPosition(model.Position);
        }