Skip to content

Instantly share code, notes, and snippets.

@Chronojam
Created January 19, 2014 15:58
Show Gist options
  • Save Chronojam/8506797 to your computer and use it in GitHub Desktop.
Save Chronojam/8506797 to your computer and use it in GitHub Desktop.
Urgh movement.
if (Ship.transform.position.x > (activeChunkPosition.x * ChunkSize) + ChunkSize/4) {
// Make a new chunk in the direction we're going.
GenerateChunk((activeChunkPosition.x + 1), activeChunkPosition.y, activeChunkPosition.z);
try {
//Clean up chunks behind us.
DeleteChunk (Chunks[new Vector3(activeChunkPosition.x - 2, activeChunkPosition.y, activeChunkPosition.z)]);
}
catch {
Debug.Log ("Just tried to delete a chunk, but we havent made it yet!");
}
// Set the ActiveChunk to the newly generated one.
ActiveChunk = Chunks[new Vector3((activeChunkPosition.x + 1), activeChunkPosition.y, activeChunkPosition.z)];
}
if (Ship.transform.position.y > (activeChunkPosition.y * ChunkSize) + ChunkSize/4) {
GenerateChunk(activeChunkPosition.x, (activeChunkPosition.y + 1), activeChunkPosition.z);
try {
DeleteChunk (Chunks[new Vector3(activeChunkPosition.x, activeChunkPosition.y - 2, activeChunkPosition.z)]);}
catch {
Debug.Log ("Just tried to delete a chunk, but we havent made it yet!");
}
// Set the ActiveChunk to the newly generated one.
ActiveChunk = Chunks[new Vector3(activeChunkPosition.x, activeChunkPosition.y + 1, activeChunkPosition.z)];
}
if (Ship.transform.position.z > (activeChunkPosition.z * ChunkSize) + ChunkSize/4) {
GenerateChunk(activeChunkPosition.x, activeChunkPosition.y, (activeChunkPosition.z + 1));
try {
DeleteChunk (Chunks[new Vector3(activeChunkPosition.x, activeChunkPosition.y, activeChunkPosition.z - 2)]);}
catch {
Debug.Log ("Just tried to delete a chunk, but we havent made it yet!");
}
// Set the ActiveChunk to the newly generated one.
ActiveChunk = Chunks[new Vector3(activeChunkPosition.x, activeChunkPosition.y, activeChunkPosition.z + 1)];
}
//// NEGATIVE MOVEMENT
/// ----------------------------------------------------------------------------------------------------------------------
if (Ship.transform.position.x < (activeChunkPosition.x * ChunkSize) - ChunkSize/4) {
// Make a new chunk in the direction we're going.
GenerateChunk((activeChunkPosition.x - 1), activeChunkPosition.y, activeChunkPosition.z);
try {
//Clean up chunks behind us.
DeleteChunk (Chunks[new Vector3(activeChunkPosition.x + 2, activeChunkPosition.y, activeChunkPosition.z)]);
}
catch {
Debug.Log ("Just tried to delete a chunk, but we havent made it yet!");
}
// Set the ActiveChunk to the newly generated one.
ActiveChunk = Chunks[new Vector3((activeChunkPosition.x - 1), activeChunkPosition.y, activeChunkPosition.z)];
Debug.Log(ActiveChunk.transform.position);
}
if (Ship.transform.position.y <(activeChunkPosition.y * ChunkSize) - ChunkSize/4) {
GenerateChunk(activeChunkPosition.x, (activeChunkPosition.y - 1), activeChunkPosition.z);
try {
DeleteChunk (Chunks[new Vector3(activeChunkPosition.x, activeChunkPosition.y + 2, activeChunkPosition.z)]);}
catch {
Debug.Log ("Just tried to delete a chunk, but we havent made it yet!");
}
// Set the ActiveChunk to the newly generated one.
ActiveChunk = Chunks[new Vector3(activeChunkPosition.x, activeChunkPosition.y - 1, activeChunkPosition.z)];
}
if (Ship.transform.position.z < (activeChunkPosition.z * ChunkSize) - ChunkSize/4) {
GenerateChunk(activeChunkPosition.x, activeChunkPosition.y, (activeChunkPosition.z - 1));
try {
DeleteChunk (Chunks[new Vector3(activeChunkPosition.x, activeChunkPosition.y, activeChunkPosition.z + 2)]);}
catch {
Debug.Log ("Just tried to delete a chunk, but we havent made it yet!");
}
// Set the ActiveChunk to the newly generated one.
ActiveChunk = Chunks[new Vector3(activeChunkPosition.x, activeChunkPosition.y, activeChunkPosition.z - 1)];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment