RaycastData RaycastAtAngle(float angle)
        {
            Vector3 direction = MMMaths.DirectionFromAngle2D(angle, 0f);

            RaycastHit2D hit2D = Physics2D.Raycast(this.transform.position, direction, VisionRadius, ObstacleMask);

            if (hit2D)
            {
                return(new RaycastData(true, hit2D.point, hit2D.distance, angle));
            }
            else
            {
                return(new RaycastData(false, this.transform.position + direction * VisionRadius, VisionRadius, angle));
            }
        }
コード例 #2
0
        protected virtual void OnSceneGUI()
        {
            // draws a circle around the character to represent the cone of vision's radius
            _coneOfVision = (MMConeOfVision2D)target;

            Handles.color = Color.yellow;
            Handles.DrawWireArc(_coneOfVision.transform.position, -Vector3.forward, Vector3.up, 360f, _coneOfVision.VisionRadius);

            // draws two lines to mark the vision angle
            Vector3 visionAngleLeft  = MMMaths.DirectionFromAngle2D(-_coneOfVision.VisionAngle / 2f, _coneOfVision.EulerAngles.y);
            Vector3 visionAngleRight = MMMaths.DirectionFromAngle2D(_coneOfVision.VisionAngle / 2f, _coneOfVision.EulerAngles.y);

            Handles.DrawLine(_coneOfVision.transform.position, _coneOfVision.transform.position + visionAngleLeft * _coneOfVision.VisionRadius);
            Handles.DrawLine(_coneOfVision.transform.position, _coneOfVision.transform.position + visionAngleRight * _coneOfVision.VisionRadius);

            foreach (Transform visibleTarget in _coneOfVision.VisibleTargets)
            {
                Handles.color = Colors.Orange;
                Handles.DrawLine(_coneOfVision.transform.position, visibleTarget.position);
            }
        }
コード例 #3
0
        RaycastData RaycastAtAngle(float angle)
        {
            _direction = MMMaths.DirectionFromAngle2D(angle, 0f);

            _raycastAtAngleHit2D = Physics2D.Raycast(this.transform.position, _direction, VisionRadius, ObstacleMask);

            if (_raycastAtAngleHit2D)
            {
                _returnRaycastData.Hit      = true;
                _returnRaycastData.Point    = _raycastAtAngleHit2D.point;
                _returnRaycastData.Distance = _raycastAtAngleHit2D.distance;
                _returnRaycastData.Angle    = angle;
            }
            else
            {
                _returnRaycastData.Hit      = false;
                _returnRaycastData.Point    = this.transform.position + _direction * VisionRadius;
                _returnRaycastData.Distance = VisionRadius;
                _returnRaycastData.Angle    = angle;
            }

            return(_returnRaycastData);
        }