Making patterns, shapes and lettters using flat gameObjects( such as tile cube)

Home Forums Game Development Questions & Discussion Making patterns, shapes and lettters using flat gameObjects( such as tile cube)

Viewing 1 reply thread
  • Author
    Posts
    • #3397 Reply
      Oshakie Ackeem Gittens
      Guest

      Soooooo this is my code. It only makes sqaure format of gameobject tiles. The Mapsize is can be anything from 10×10 ,10×15, 20×20 etc..

      public class FloorGenerator : MonoBehaviour {
          public Transform tilePrefab;
          public Vector2 mapSize;
      
          [Range(0,1)]
          public float outlinePercent;
      
          void Awake(){
              if (Manager.Instance.sceneIndex == 5) {
                  /*assigns the mapSize from Manager class*/
                  mapSize = Manager.Instance.InitializeMapSize;
              }
          }
      
          void Start() {
              GenerateMap ();
          }
      
          public Vector2 GetMapSize{
              get{return mapSize;}
          }
      
          public void GenerateMap() {
              string holderName = "Generated Map";
              if (transform.Find (holderName)) {
                  DestroyImmediate(transform.Find(holderName).gameObject);
              }
              Transform mapHolder = new GameObject (holderName).transform;mapHolder.parent = transform;
              /*retreives all floor prefrabs*/
              mapHolder.gameObject.AddComponent<GeneratedMap> ();
              for (int x = 0; x < mapSize.x; x ++) {
                  for (int y = 0; y < mapSize.y; y ++) {
                      Vector3 tilePosition = new Vector3(-mapSize.x/2 +0.5f + x, 0, -mapSize.y/2 + 0.5f + y);
                      Transform newTile = Instantiate(tilePrefab, tilePosition, Quaternion.Euler(Vector3.right*90)) as Transform;
                      newTile.localScale = Vector3.one * (1-outlinePercent);newTile.parent = mapHolder;
                  }
              }
          }
      }

       

    • #3401 Reply
      Rashid Ellis
      Moderator

      Wow! You took this and was able to implement with precision!

      This is actually the basic concept for voxel environments in games such as Minecraft. The difference is that the grid is implemented using a 3-dimensional array.

      Now that you have the basic concept for this, you can do this using any method you know to create any combination of shapes by instantiating entities that pass any type of validation. You can use any type of algorithm, picture, or pattern for this. (I.E.: picture of John Cena, or and troll face.)

      ah HA!

      Later, if you want to go on to create larger and more complex shapes and behaviors, you can look into how to define basic primitives, (All boxes inside the volume return true.) In your case, You can animate the grid’s appearance by validating with a circle (Or the distance to a point that has its Transform changing per frame.)

      Or create interesting particle effects. Let me know if you have additional questions!

Viewing 1 reply thread
Reply To: Making patterns, shapes and lettters using flat gameObjects( such as tile cube)
Your information: