Results 1 to 3 of 3
  1. #1
    Join Date
    Sep 2011
    Posts
    2

    lees terrain R&D part 3 problem

    Hi all
    im new to this i signed up to learn about making games and have been working thought the mmo tutorials but hit a problem i can get the spheres to show but not the same as lee did heres a pic of my screen shot

    Click image for larger version. 

Name:	errorzw.jpg 
Views:	135 
Size:	60.2 KB 
ID:	73026

    my code is as follows
    Code:
    using System.Collections.Generic;
    using UnityEngine;
    
    namespace _CodeBase.Demos
    {
        public class TerrainPatch
        {
            private List<Vector3> Vertices = new List<Vector3>();
    
            public int Size { get; set; }
            public float Spacing { get; set; }
    
            public TerrainPatch(int size, float spacing)
            {
                Size = size;
                Spacing = Spacing;
    
                //Create the Grid.
                CreateGrid();
            }
    
           public void CreateGrid()
            {
                var index = 0;
    
                for (int z = 0; z < Size; z++)
                {
                    if (z % 2 == 0)
                    {
                        for (int x = 0; x < Size; x++)
                        {
                            Vertices.Add(new Vector3(x * Spacing, 0, z * Spacing));
    
                            index++;
                        }
                    }
                    else
                    {
                        for (int x = 0; x < Size + 1; x++)
                        {
                            var posX = x * Spacing - Spacing / 2;
    
                            if (posX < 0)
                                posX = 0;
    
                            if (posX > (Size - 1) * Spacing)
                                posX = (Size - 1) * Spacing;
    
                            Vertices.Add(new Vector3(posX, 0, z * Spacing));
    
                            index++;
                        }
     
                    }
    
                }
    
                foreach (var vertex in Vertices)
                {
                    GameObject tempGO = GameObject.CreatePrimitive(PrimitiveType.Sphere);
                    tempGO.transform.localScale = new Vector3(0.1f, 0.1f, 0.1f);
                    tempGO.transform.position = vertex; 
                }
    
                
            }
    
            public void DrawGrid()
            {
                Debug.DrawLine(Vertices[0], Vertices[Size]);
                Debug.DrawLine(Vertices[Size], Vertices[Size + 1]);
                Debug.DrawLine(Vertices[Size + 1], Vertices[0]);
            }
        }
    }
    can anyone please tell me where iv gone wrong as i re-watched the videos 5 times now
    thanks in advance

  2. #2
    Join Date
    Sep 2008
    Location
    Salisbury, UK
    Posts
    2,812
    Code:
    Spacing = Spacing;
    should be
    Code:
    Spacing = spacing;

    I found
    my current avatar on google, so props to THIS GUY who created the original...

  3. #3
    Join Date
    Aug 2011
    Location
    Manassas, VA
    Posts
    39
    You have Spacing = Spacing. Shouldn't it be Spacing = spacing?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •