@dave1707 Pursuant to my question about whether anybody had made anything you could walk around in, I tried to take your terrain and make it something I could walk around in.
I just kind of did a hacky thing where I cut and pasted some code from the Voxel Terrain project, and it kind of works, kinda.
Unfortunately when I spawn the player, it turns all the blocks to water or ice. Or something blue.
After the player spawns you will have to press play to resume running, because for some reason it pauses. And it may look like all you see is blue, but if you swipe around you’ll eventually see sky also.
displayMode(FULLSCREEN)
function setup()
assert(SEA_LEVEL, "Please include Voxel Terrain as a dependency")
scene = craft.scene()
viewer=scene.camera:add(OrbitViewer,vec3(100,0,0), 300, 0, 10000)
viewer.rx=30
sprite()
scene.voxels.blocks:addAssetPack("Blocks")
dirtgrass = scene.voxels.blocks:new("DirtGrass")
dirtgrass.setTexture(ALL, "Blocks:Dirt Grass")
water = scene.voxels.blocks:new("Water")
water.setTexture(ALL, "Blocks:Water")
snow = scene.voxels.blocks:new("Snow")
snow.setTexture(ALL, "Blocks:Snow")
grass = scene.voxels.blocks:new("Grass Top")
grass.setTexture(ALL, "Blocks:Grass Top")
scene.voxels.visibleRadius=20
scene.voxels:resize(vec3(30,1,30))
scene.voxels.coordinates = vec3(100,0,100)
offsetX=3
offsetZ=1
dirtLevel=25
grassLevel=10
waterLevel=2
val=200
m=1/val
h=craft.noise.perlin()
xx,zz=0,0
for x=1,val do
xx=xx+m
zz=0
for z=1,val do
zz=zz+m
y=math.abs(h:getValue(xx+offsetX,0,zz+offsetZ))*50//1
if y>dirtLevel then
scene.voxels:fill("Snow")
scene.voxels:block(x,y,z)
elseif y>grassLevel then
scene.voxels:fill("DirtGrass")
scene.voxels:block(x,y,z)
elseif y>waterLevel then
scene.voxels:fill("Grass Top")
scene.voxels:block(x,y,z)
else
scene.voxels:fill("Water")
scene.voxels:block(x,waterLevel,z)
end
end
end
-- Get a list of all loaded blocks
allBlocks = scene.voxels.blocks:all()
-- Spawn a player to explore the terrain
parameter.action("Spawn Player", function()
if viewer == nil then return end
-- Use the current camera position as the target location to spawn the player
local pos = vec3( viewer.target:unpack() )
pos.y = 128
-- Disable the initial viewer so it doesn't fight with the player one
touches.removeHandler(viewer)
scene.camera:remove(viewer)
viewer = nil
-- Get surface position using a raycast
scene.voxels:raycast(pos, vec3(0,-1,0), 128, function(coord, id, face)
if id and id ~= 0 then
pos.y = coord.y + 2
return true
end
end)
-- Create a basic player
player = scene:entity():add(BasicPlayer, scene.camera:get(craft.camera), pos:unpack())
-- Re-enable fog
scene.fogEnabled = true
-- Make the display fullscreen for first person mode
viewer.mode = FULLSCREEN
print("Project has paused, press play to resume.")
end)
--[[
allBlocks = blocks()
player = scene:entity():add(BasicPlayer, scene.camera:get(craft.camera), 40, 20, 40)
]]
end
function update(dt)
scene:update(dt)
end
function draw()
update(DeltaTime)
scene:draw()
if player then
player:draw()
end
end