Ejemplo n.º 1
0
        private void TakeControlOverTargetAi()
        {
            _controlledAi?.WithdrawControl(this);

            // Not a fan of using the Gun's CreateRay here, as it's not related to the gun.
            Ray ray = gun.CreateRay();

            bool hitSomething = RayCaster.CastRay(ray, float.MaxValue, out RaycastHit hit);

            if (!hitSomething)
            {
                return;
            }

            var aiController = hit.transform.GetComponent <BaseAiController>();

            if (aiController == null)
            {
                return;
            }


            _controlledAi = aiController;

            Logging.Log($"Gotcha, {_controlledAi.name}!");

            _controlledAi.TakeControl(this);
        }
Ejemplo n.º 2
0
        private void CreateVisualizerAtTargetPosition()
        {
            // Not a fan of using the Gun's CreateRay here, as it's not related to the gun.
            Ray ray = gun.CreateRay();

            bool hitSomething = RayCaster.CastRay(ray, float.MaxValue, out RaycastHit hit);

            if (!hitSomething)
            {
                return;
            }

            Vector3 hitPoint = hit.point;

            const float yDistAboveGround = 5;

            hitPoint.y += yDistAboveGround;

            VisualizerBase visualizer = Instantiate(testVisualizer, hitPoint, Quaternion.identity);

            Transform visualizerTransform = visualizer.transform;

            visualizerTransform.LookAt(transform);

            Vector3 currRot = visualizerTransform.rotation.eulerAngles;

            visualizer.transform.rotation = Quaternion.Euler(0, currRot.y, 0);

            if (_controlledAi == null)
            {
                return;
            }

            _controlledAi.ForceRequestPathTo(hit.point);
        }
Ejemplo n.º 3
0
        private bool CanSeeTarget(Entity target)
        {
            var vector      = target.Location - Location;
            var maxDistance = (int)Math.Min(vector.Length, 500);

            var result = RayCaster.CastRay(Services.Game.Level, Location, vector, CollisionCheckType.BlocksProjectiles, maxDistance);

            return(!result.Hit);
        }
        public Tuple <IInteractable, RaycastHit> GetInteractableFromRay(Ray ray, float range)
        {
            if (!RayCaster.CastRay(ray, range, out RaycastHit hit))
            {
                return(null);
            }
            var interactable = hit.transform.GetComponent <IInteractable>();

            return(interactable == null ? null : new Tuple <IInteractable, RaycastHit>(interactable, hit));
        }
Ejemplo n.º 5
0
        private static bool CheckIfCollidingOnX(Vector3 pos, float dist)
        {
            var ray = new Ray(pos, dist > 0 ? Vector3.right : Vector3.left);

            return(RayCaster.CastRay(ray, Mathf.Abs(dist)));
        }
Ejemplo n.º 6
0
        private static bool CheckIfCollidingOnZ(Vector3 pos, float dist)
        {
            var ray = new Ray(pos, dist > 0 ? Vector3.forward : Vector3.back);

            return(RayCaster.CastRay(ray, Mathf.Abs(dist)));
        }
Ejemplo n.º 7
0
        private static bool CheckIfCollidingVertical(Vector3 pos, float dist)
        {
            var ray = new Ray(pos, dist > 0 ? Vector3.up : Vector3.down);

            return(RayCaster.CastRay(ray, Mathf.Abs(dist)));
        }