Here’s a little example showing Craft physics.
supportedOrientations(LANDSCAPE_ANY)
function setup()
assert(craft, "Please include Craft as a dependency")
assert(OrbitViewer, "Please include Cameras (not Camera) as a dependency")
parameter.number("opac",0,.7)
size=1
fill(255)
scene = craft.scene()
skyMaterial=scene.sky.material
skyMaterial.sky=color(0, 62, 255, 255)
skyMaterial.horizon=color(99, 255, 0, 255)
scene.sun.rotation=quat.eulerAngles(20,45,-30)
createObjects()
v=scene.camera:add(OrbitViewer, vec3(0,0,0), 30, 0, 20)
end
function createObjects()
sphere1=scene:entity()
s1=sphere1:add(craft.rigidbody,DYNAMIC)
s1.linearVelocity=vec3(2,2,2)
s1.restitution=1
s1.friction=0
sphere1.position=vec3(-3,3,1)
sphere1:add(craft.shape.sphere,size)
sphere1.model = craft.model.icosphere(size,2)
sphere1.material = craft.material("Materials:Specular")
sphere1.material.diffuse=color(255,0,0)
sphere2=scene:entity()
s2=sphere2:add(craft.rigidbody,DYNAMIC)
s2.linearVelocity=vec3(3,4,3)
s2.restitution=1
s2.friction=0
sphere2.position=vec3(-5,0,3)
sphere2:add(craft.shape.sphere,size)
sphere2.model = craft.model.icosphere(size,2)
sphere2.material = craft.material("Materials:Specular")
sphere2.material.diffuse=color(0,0,255)
wall1=createWall(1,vec3(-5,0,0),vec3(.1,10,10),vec3(.1,10,10),"Blocks:Error")
wall2=createWall(1,vec3(5,0,0),vec3(.1,10,10),vec3(.1,10,10),"Blocks:Dirt Sand")
wall3=createWall(1,vec3(0,-5,0),vec3(10,.1,10),vec3(10,.1,10),"Blocks:Cotton Blue")
wall4=createWall(1,vec3(0,0,5),vec3(10,10,.1),vec3(10,10,.1),"Blocks:Cactus Side")
wall5=createWall(1,vec3(0,0,-5),vec3(10,10,.1),vec3(10,10,.1),"Blocks:Brick Red")
wall6=createWall(1,vec3(0,5,0),vec3(10,.1,10),vec3(10,.1,10),"Blocks:Brick Grey")
end
function createWall(rest,pos,a,mod,map)
local ww=scene:entity()
local w=ww:add(craft.rigidbody,STATIC)
w.restitution=rest
ww.position=pos
ww:add(craft.shape.box,a)
ww.model = craft.model.cube(mod)
ww.material = craft.material("Materials:Standard")
ww.material.map = readImage(map)
ww.material.blendMode = NORMAL
return ww
end
function draw()
update(DeltaTime)
scene:draw()
text("Move the slider to change opacity",WIDTH/2,HEIGHT-50)
text("Drag your finger on the screen to rotate the cube",WIDTH/2,HEIGHT-100)
end
function update(dt)
scene:update(dt)
wall1.material.opacity=opac
wall2.material.opacity=opac
wall3.material.opacity=opac
wall4.material.opacity=opac
wall5.material.opacity=opac
wall6.material.opacity=opac
end