1. Hello everyone,

    I'm developping a plugin that use a map grid, for that i divided the map on 26 part using MapSize/26 then i inserted everypart to a List<class> to store PartName, lessLimit and plusLimit.

    Code:
            private List<GridSection> grid = new List<GridSection>();        class GridSection
            {
                public string name { get; set; }
                public Vector3 lessPosition { get; set; }
                public Vector3 plusPosition { get; set; }        }
    
    Code:
            List<GridSection> IsClaimed(Vector3 position)
            {
                var name = grid.FindAll(x =>
                    (x.lessPosition.x < position.x && x.lessPosition.z > position.x) &&
                    (x.plusPosition.x > position.x);            return name;
            }
            var claimedname = IsClaimed(entity.transform.position);
            if (claimedname != null)
            {
                foreach (var VARIABLE in claimedname)
                {
                    Puts(VARIABLE.name);
                 }
            }
    
    I'am trying to use FindAll() to get the tile but it return me more than on value at the current time, i guess i just miss something but i don't know what.
     
    Last edited by a moderator: Apr 22, 2018
  2. I did not understand what do you want, maybe cause of language barrier. But, as i see in title, you need choose closest point?
    You can use Vector3.Distance(1vector3, 2vector3).
     
  3. Yeah I need to find the closest point from a list a stored vector3, I'll try to use distance, but I'll need to loop thought every stored value

    Exemple:

    My list contains the following:
    (A1
    lessLimit 100 0 100
    plusLimit 200 0 200)
    (A2
    lessLimit 200 0 200
    plusLimit 300 0 300)
    (A3
    lessLimit 300 0 300
    plusLimit 400 0 400)

    If my cupboard has the position 250 0 300
    How I get sort A2 tile from the list ?

    Sorry for my English :/
     
  4. upload_2018-4-22_14-23-24.png
    If i remember right, you can create Rect and then use functions Contains.

    If making it better and integrate in your situation with lsit.
    upload_2018-4-22_14-28-10.png
    Where newVector class is:
    upload_2018-4-22_14-28-27.png

    Z instead of Y, and probably instead of right.y, you will need to use right.y-left.y, cause it is height.... Check, i gave basics idea
     

    Attached Files:

    Last edited by a moderator: Apr 22, 2018
  5. I'll try it and let you know, thanks for the tips
     
  6. Don't know if it's the best way, but i get it using this :

    Code:
            bool IsClaimed(Vector3 position)
            {
                string name = grid.Find(section => section.lessPosition.x > position.x && section.lessPosition.x < position.x + mapSize / 26 && section.lessPosition.z > position.z && section.lessPosition.z < position.z + mapSize / 26).name;
                return claimedLand.Find(x => x.claimed.Contains(name)) != null;
            }
    
     
  7. upload_2018-4-22_23-30-42.png
    You dont need to make mapsize/26 each time, just right uppercorner y - left bottom corner y
     

    Attached Files:

  8. Isn't this just what you want?
    Code:
            private Vector3 FindClosestPoint(Vector3 startingPoint, IEnumerable<Vector3> points) =>
                points.OrderBy(x => Vector3.Distance(startingPoint, x))
                .First();
    EDIT: If it's a rectangle/square just find the center with midpoint formula, or some Unity Vector3 helper, then find the closest from that list.
     
    Last edited by a moderator: Apr 23, 2018
  9. You might want to look at WorldSpaceGrid and its usage in ColliderGrid. WorldSpaceGrid sounds like it would do what you want right out of the box (divide map, associate an object to each cell, and translate cell coordinates to/from world coordinates).