Quick Fix for Vector3.zero


I’ve been having this problem throughout the whole lecture cause I didn’t build exterior walls, but it finally bothered me enough to throw together a quick fix. Basically, clicking on a space that’s not on the grid would do an action on 0, 0 if that was part of the valid grid. In the provided screenshot, the tiles above can still be moved to, but because the floor they’re on is disabled clicking on it will end up clicking outside the grid and send my unit running to 0, 0.

The fix I put together was pretty simple, I just changed Vector3.zero to this:

        Vector3 invalidPosition = new Vector3(float.MaxValue, float.MaxValue, float.MaxValue);
        return invalidPosition;

It’s probably not the best solution, but it gets the job done for now. Now how I actually want to handle those grid visuals floating up there is a different question entirely, I’ll probably implement the semi-transparent materials idea that was suggested in a previous video.

And immediately after posting I found this.

 Vector3 invalidPosition = Vector3.positiveInfinity;
        return invalidPosition;

Privacy & Terms