Limit playable area

Modified on Thu, 23 Mar 2023 at 11:04 PM

For example, say you want to limit the playable area to a 200x200x200 box around zero world position (0,0,0):


1. Select FPSController and disable "Start On Flat". By default, this option will spawn the player on a flat and random position. The random position depends on the world seed. So it will only change if you change the seed. Note that Voxel Play will always spawn the player on top of the surface.


2. Move the FPSController position to (0,0,0) using the transform position fields in the inspector.


3. Scroll down and tick the "Limit Bounds Enabled" checkbox and enter the playable area size in the Limit Bounds fields.


That's it!

Step by step video:





Also, if you don't want to render any chunk beyond the extents area, you have 2 options:


1. Recommended: uncheck the "Infinite" toggle in the World Definition fields and set World Extents to 200x200x200 in World Definition:



2. Or you can add this script to FPSController gameobject which basically overrides the chunk contents with empty voxels:


using UnityEngine;
using VoxelPlay;

public class LimitArea : MonoBehaviour {

    VoxelPlayEnvironment env;

    void Start () {
        env = VoxelPlayEnvironment.instance;

        env.OnChunkBeforeCreate += (Vector3d chunkCenter, out bool overrideDefaultContents, VoxelChunk chunk, out bool isAboveSurface) => {
            const float MAX_DISTANCE = 100;
            float dx = Mathf.Abs (chunkCenter.x);
            float dy = Mathf.Abs (chunkCenter.y);
            float dz = Mathf.Abs (chunkCenter.z);
            if (dx > MAX_DISTANCE || dy > MAX_DISTANCE || dz > MAX_DISTANCE) {
                overrideDefaultContents = true;
                /* Here you could provide your own voxels setting the chunk.voxels array for the chunk which is 16x16x16. If you don't provide any voxels, the chunk will be empty */
            } else {
                overrideDefaultContents = false;
            }
            isAboveSurface = true;
        };
    }
     
}





Was this article helpful?

That’s Great!

Thank you for your feedback

Sorry! We couldn't be helpful

Thank you for your feedback

Let us know how can we improve this article!

Select atleast one of the reasons

Feedback sent

We appreciate your effort and will try to fix the article