Hey guys,
I need a bit of help to speed up my search algorithms.
What I want to do is this, I have a fixed size of Chunks in a List. Those Chunk scripts have information about their position.
So to find a Chunk what I’m doing is this
public static Chunk FindChunk(Vector3 worldPosition) {
foreach (Chunk ch in chunks) {
if (worldPosition.x < ch.position.x || worldPosition.y < ch.position.y || worldPosition.x >= ch.position.x + CHUNK_WIDTH || worldPosition.y >= ch.position.y + CHUNK_HEIGHT) {
continue;
}
return ch;
}
return null;
}
Is there any way to speed this up? Especially because I have to access the neighbors very often.
Thanks!