Number overflow
i have no clue what is wrong here..iv looked and the script looks ok but when i hit play i get Number overflow
public class Grid : MonoBehaviour {
public Vector2 gridworldsize;
public float noderadice;
public LayerMask unwalkable;
Nodeclass[,] grid;
float nodeDiamater;
int gridSizeX, gridSizeY;
void Start () {
nodeDiamater = noderadice * 2;
gridSizeX = Mathf.RoundToInt (gridworldsize.x / nodeDiamater);
gridSizeY = Mathf.RoundToInt (gridworldsize.y / nodeDiamater);
CreateGrid ();
}
void CreateGrid (){
grid = new Nodeclass[gridSizeX,gridSizeY];
Vector3 worldbottomleft = transform.position - Vector3.right * gridworldsize.x / 2 - Vector3.forward * gridworldsize.y / 2;
for (int x = 0; x < gridSizeX; x++) {
for (int y = 0; y < gridSizeY; y++) {
Vector3 worldpoint = worldbottomleft + Vector3.right * (x * nodeDiamater + noderadice) + Vector3.forward * (y * nodeDiamater + noderadice);
bool walkable = !(Physics.CheckSphere (worldpoint, noderadice));
grid [x, y] = new Nodeclass (walkable, worldpoint);
print ("this is now working");
}
}
}
void OnDrawGizmos(){
Gizmos.DrawWireCube(transform.position,new Vector3 (gridworldsize.x,1,gridworldsize.y));
if (grid != null) {
foreach (Nodeclass n in grid) {
Gizmos.color = (n.walkable) ? Color.white : Color.red;
Gizmos.DrawCube (n.worldPosition, Vector3.one * (nodeDiamater - .1f));
}
}
}
}
what is wrong with it?
What values have you assigned to nodeDiamater, gridSizeX, gridSizeY etc.?
in the object i have it in i have X -166.1 Y -167.9
and Noderadice 0.5
its as big as the map it self
Answer by tanoshimi · Nov 05, 2016 at 02:04 PM
With the additional information supplied in your comment, the problem becomes obvious - in the following line you're trying to instantiate a negatively-sized array:
grid = new Nodeclass[gridSizeX,gridSizeY];
alright..so would the fix be just have it be positive numbers? or have the gridsize be negative? (im following a tourutal on YouTube for this path-finding..im very new to scripting :P)
Your answer
Follow this Question
Related Questions
0xc000007b error on 64 bit machine? 1 Answer
Position is infinite 0 Answers
Unity Package Manager Error 4 Answers