Tip for dynamic map scale in MoveCamera

Hey so if you’re like me and never want to hardcode anything, do this instead of using the mapScale variable. You can cache a reference to your “Floor” BoxCollider in your Minimap script, and then use it to dynamically match the size of your level when moving on the minimap.

In the MoveCamera method, you just need to calculate newCamPos like this instead of what the video gives:

        Vector3 newCamPos = new Vector3(
            Mathf.Lerp(-_floor.bounds.extents.x, _floor.bounds.extents.x, lerp.x),
            _cameraTransform.transform.position.y,
            Mathf.Lerp(-_floor.bounds.extents.z, _floor.bounds.extents.z, lerp.y));

Hope that helps someone solve a problem that doesn’t quite exist yet :sweat_smile:

3 Likes

Privacy & Terms