Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

How to draw grid on plane.

Discussion in 'Scripting' started by unity_SqKRi3Klpu8M1w, Oct 31, 2019.

  1. unity_SqKRi3Klpu8M1w

    unity_SqKRi3Klpu8M1w

    Joined:
    Oct 21, 2019
    Posts:
    11
    Hi everyone!
    I have a plane. And I have a crowd like picture below.
    I want to arrange the crowd as much as possible into the plane below.
    I plan to create a grib position where will be destination of agent and calculate the number that can be stored agents based on the plane size and agent size. (I just know size of box collider of plane and agent.
    But I don't know how to create points( draw a grib) on that plane. Please help me, thanks.
    (Ps: I am try to make a game like
    )
     

    Attached Files:

  2. Pavlon

    Pavlon

    Joined:
    Apr 15, 2015
    Posts:
    191
  3. unity_SqKRi3Klpu8M1w

    unity_SqKRi3Klpu8M1w

    Joined:
    Oct 21, 2019
    Posts:
    11
    Thanks for reply, but I think I cant use AI pathfinding of navmesh.
    Currently, I am stucking at create a list of position, create a grid on a plane. :((
     
  4. unity_SqKRi3Klpu8M1w

    unity_SqKRi3Klpu8M1w

    Joined:
    Oct 21, 2019
    Posts:
    11
    Hi everyone.
    I created a grid where can stored the largest number of agent. I want to it place at on floor. But it is in-correcting.
    How can I fix it, thanks a lot!
    Code (CSharp):
    1.   private void OnDrawGizmos()
    2.     {
    3.  
    4.         Gizmos.color = Color.yellow;
    5.         int sizeX = Mathf.RoundToInt(transform.lossyScale.x / agent.lossyScale.x);
    6.         int sizeZ = Mathf.RoundToInt(transform.lossyScale.z / agent.lossyScale.z);
    7.  
    8.         for (int i = 0; i < sizeX; i++)
    9.         {
    10.             for (int z = 0; z < sizeZ; z++)
    11.             {
    12.                 var point = new Vector3(agent.lossyScale.x * i, 0f, agent.lossyScale.z * z);
    13.                 Gizmos.DrawCube(transform.position + point, agent.lossyScale);
    14.  
    15.             }
    16.         }
    17.     }
     

    Attached Files:

    • abc.png
      abc.png
      File size:
      305.1 KB
      Views:
      391
  5. Pavlon

    Pavlon

    Joined:
    Apr 15, 2015
    Posts:
    191
    You can use https://docs.unity3d.com/ScriptReference/Transform.TransformPoint.html .

    Create a new Vector3 (i,0,z) and multiply it with the GRIDOBJECT.transform.TransformPoint where the GRIDOBJECT is at the position where you want the grid to be pointing forward to the road.

    EDIT: not sure maby https://docs.unity3d.com/ScriptReference/Transform.TransformVector.html is the right one.

    Also I guess its easier to align your objects to the grid then the grid to a object.

    May be you should make a grid that represents the passenger area and vehicle at the same time this could save you some trouble later on.
     
    Last edited: Oct 31, 2019