Exemple #1
0
        /// <inheritdoc />
        public override void CastPoints()
        {
            if (!isActiveAndEnabled)
            {
                return;
            }

            Ray        ray = new Ray(transform.position, transform.forward);
            RaycastHit hitData;
            bool       hasCollided = PhysicsCast.Raycast(physicsCast, ray, out hitData, maximumLength, Physics.IgnoreRaycastLayer);

            TargetHit = (hasCollided ? hitData : (RaycastHit?)null);

            points[0] = transform.position;
            points[1] = (hasCollided ? hitData.point : transform.position + transform.forward * maximumLength);

            ResultsChanged?.Invoke(eventData.Set(TargetHit, Points));
        }
Exemple #2
0
        /// <summary>
        /// Checks for collisions along the parabolic line segments and generates the final points.
        /// </summary>
        /// <param name="forward">The forward direction to use for the checks.</param>
        /// <param name="down">The downwards direction to use for the checks.</param>
        protected virtual void GeneratePointsIncludingSegments(Vector3 forward, Vector3 down)
        {
            GeneratePoints(forward, down);

            collisionCheckFrequency = Mathf.Clamp(collisionCheckFrequency, 0, segmentCount);
            int step = segmentCount / (collisionCheckFrequency > 0 ? collisionCheckFrequency : 1);

            for (int index = 0; index < segmentCount - step; index += step)
            {
                Vector3 currentPoint       = points[index];
                Vector3 nextPoint          = index + step < points.Count ? points[index + step] : points[points.Count - 1];
                Vector3 nextPointDirection = (nextPoint - currentPoint).normalized;
                float   nextPointDistance  = Vector3.Distance(currentPoint, nextPoint);

                Ray        pointsRay = new Ray(currentPoint, nextPointDirection);
                RaycastHit pointsHitData;

                if (!PhysicsCast.Raycast(physicsCast, pointsRay, out pointsHitData, nextPointDistance, Physics.IgnoreRaycastLayer))
                {
                    continue;
                }

                Vector3    collisionPoint = pointsRay.GetPoint(pointsHitData.distance);
                Ray        downwardRay    = new Ray(collisionPoint + Vector3.up * 0.01f, Vector3.down);
                RaycastHit downwardHitData;

                if (!PhysicsCast.Raycast(physicsCast, downwardRay, out downwardHitData, float.PositiveInfinity, Physics.IgnoreRaycastLayer))
                {
                    continue;
                }

                TargetHit = downwardHitData;

                Vector3 newDownPosition  = downwardRay.GetPoint(downwardHitData.distance);
                Vector3 newJointPosition = newDownPosition.y < forward.y ? new Vector3(newDownPosition.x, forward.y, newDownPosition.z) : forward;
                GeneratePoints(newJointPosition, newDownPosition);

                break;
            }

            ResultsChanged?.Invoke(eventData.Set(TargetHit, Points));
        }
Exemple #3
0
 /// <inheritdoc />
 protected override void DoCastPoints()
 {
     GeneratePoints();
     ResultsChanged?.Invoke(eventData.Set(TargetHit, Points));
 }