Ejemplo n.º 1
0
        // Due to how it's constructed, it can never collide purely on the horizontal axis. If there is a X-Z collision, then the marker would simply not be created in the first place
        private static bool CheckIfColliding(Vector3 markerPos, AdjacencyDirection direction, float xDist, float zDist, float yDist)
        {
            // 'Marker' is referring to the marker whose 'connectedMarkers' list is being worked on.
            // 'Object' is referring to the marker that we're checking line-of-sight towards.

            // Keep this in mind while reading this:
            // 'Marker' and 'Object' *are* next to each other, that's how they were created.

            // Small illustration: [O = 'Object', M = 'Marker', C = Collider that the marker was created on (C will always be there)]

            // In the first scenario, if M cast a ray downwards, it'll always collide with C. Therefore, we need to start by casting the ray 'along the floor' before going down.
            // Conversely, in the second scenario, casting a ray along the floor will always collide with C. Therefore, we need to start by casting the ray upwards

            //  M ->					O <--
            //		v						^
            //  C	O					C	M

            var yCollides = false;
            var xCollides = false;
            var zCollides = false;


            // 'Object' is above
            if (yDist > 0)
            {
                // y first
                yCollides = CheckIfCollidingVertical(markerPos, yDist);

                if (yCollides)
                {
                    return(true);
                }

                Vector3 newPos = markerPos;
                newPos.y += yDist;

                CheckIfCollidingHorizontal(newPos, direction, xDist, zDist, ref zCollides, ref xCollides);
            }

            // 'Object' is underneath
            else
            {
                // x or z first
                CheckIfCollidingHorizontal(markerPos, direction, xDist, zDist, ref zCollides, ref xCollides);

                if (zCollides || xCollides)
                {
                    return(true);
                }

                Vector3 newPos = markerPos;
                newPos.x += xDist;
                newPos.z += zDist;

                yCollides = CheckIfCollidingVertical(newPos, yDist);
            }


            return(yCollides || xCollides || zCollides);
        }
Ejemplo n.º 2
0
        private static void CheckIfCollidingHorizontal(Vector3 point, AdjacencyDirection direction, float xDist, float zDist, ref bool zColl, ref bool xColl)
        {
            switch (direction)
            {
            case AdjacencyDirection.Forward:
            case AdjacencyDirection.Back:
                zColl = CheckIfCollidingOnZ(point, zDist);
                xColl = false;
                break;

            case AdjacencyDirection.Left:
            case AdjacencyDirection.Right:
                xColl = CheckIfCollidingOnX(point, xDist);
                zColl = false;
                break;

            case AdjacencyDirection.ForwardRight:
            case AdjacencyDirection.BackRight:
            case AdjacencyDirection.BackLeft:
            case AdjacencyDirection.ForwardLeft:
                // LOW-PRIO: Need to check both X->Z->Y *AND* Z->X->Y
                break;

            case AdjacencyDirection.Unknown:
            default:
                Logging.LogError("Something terrible has happened here");
                break;
            }
        }
Ejemplo n.º 3
0
 public MarkerStats(PathfindingMarker marker, float yDist, AdjacencyDirection direction)
 {
     this.marker       = marker;
     yDistance         = yDist;
     relativeDirection = direction;
 }
Ejemplo n.º 4
0
        // This will throw an error if you delete the markers during the coroutine, but that's entirely user-error, and I'm fine with that for now.
        private IEnumerator GenerateMarkerConnectionsWithCoroutines()
        {
            var generationsThisFrame = 0;

            foreach (PathfindingMarker marker in grid.markers)
            {
                generationsThisFrame++;

                if (generationsThisFrame % markerConnectionsToGeneratePerFrame == 0)
                {
                    yield return(null);
                }
                // F	^ = 0
                // F/R	^> = 1
                // R	> = 2
                // B/R	v> = 3
                // B	v = 4
                // B/L	<v = 5
                // L	< = 6
                // F/L	<^ = 7

                // NULL = 'Out of Bounds', or 'Inside Wall'

                var connectedMarkers = new List <MarkerStats>();

                Vector3 markerPos = marker.transform.position;

                foreach (PathfindingMarker marker2 in grid.markers)
                {
                    if (marker2 == marker)
                    {
                        continue;
                    }

                    Vector3 marker2Pos = marker2.transform.position;

                    float xDist = marker2Pos.x - markerPos.x;
                    if (Mathf.Abs(xDist) > distanceBetweenCreatedMarkers)
                    {
                        continue;
                    }

                    float zDist = marker2Pos.z - markerPos.z;
                    if (Mathf.Abs(zDist) > distanceBetweenCreatedMarkers)
                    {
                        continue;
                    }

                    if (Math.Abs(xDist) < 0.1f && Math.Abs(zDist) < 0.1f)
                    {
                        continue;
                    }


                    float yDist = marker2Pos.y - markerPos.y;

                    // Have to be checked prior to the x and y, because those would depend on this. If it's too far above, then it's a fail, but if it's too far below, then it's fine (up to a point - You can fall a lot further than you can jump)
                    // if (!CheckValidHeightDifference(yDist)) continue;

                    AdjacencyDirection direction = FindRelativeDirection(xDist, zDist);
                    if (direction == AdjacencyDirection.Unknown)
                    {
                        Logging.LogWarning("Unknown direction");
                        yield break;
                    }

                    if (CheckIfColliding(markerPos, direction, xDist, zDist, yDist))
                    {
                        continue;
                    }

                    // if (connectedMarkers[(int) direction] != null)
                    // {
                    //  Logging.LogWarning($"Somehow there's already a marker on {marker}'s connectedMarker {direction} direction");
                    //  continue;
                    // }

                    connectedMarkers.Add(new MarkerStats(marker2, yDist, direction));

                    // connectedMarkers[(int) direction] = new MarkerStats(marker2, yDist);
                }

                marker.connectedMarkers = connectedMarkers;
            }
        }