3D Spawning System

One of the things that I am trying to make at the moment, is a spawning system that spawns a 3D object into the world every second. How am I supposed to achieve this goal???

Thanks in advance :slight_smile:

viewer.mode=FULLSCREEN

function setup()
    assert(OrbitViewer, "Please include Cameras as a dependency")        
    scene = craft.scene()    
    v=scene.camera:add(OrbitViewer,vec3(0,0,0), 300, 0, 1000)
    cnt=0
end

function draw()
    update(DeltaTime)
    scene:draw() 
    cnt=cnt+1
    if cnt>=60 then
        createSphere(vec3(math.random(-50,50),math.random(-50,50),math.random(-50,50)))
        cnt=0
    end
end

function update(dt)
    scene:update(dt)
end

function createSphere(p)
    local s=scene:entity()
    s.position=vec3(p.x,p.y,p.z)
    s.model = craft.model.icosphere(2,3)
    s.material = craft.material(asset.builtin.Materials.Specular)
    s.material.diffuse=color(255,0,0)
end

@dave1707, thank you very much for that code, it helped out quite a lot!

This is why I love codea. It’s so streamlined.