@threads I took one of my projects and modified it to attach a camera to one of the objects. Tap the attach parameter to attach or release the camera. I still haven’t been able to alter the camera position relative to the object.
PS. Added code to allow the attached camera to be rotated using the parameter sliders.
function setup()
opac=.3
parameter.action("attach",attach)
parameter.integer("angX",0,360,0)
parameter.integer("angY",0,360,0)
parameter.integer("angZ",0,360,0)
size=.2
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, 200)
v.rx=30
v.ry=30
end
function attach()
if not aa then
aa=scene:entity()
s1=aa:add(craft.rigidbody,DYNAMIC)
s1.linearVelocity=vec3(2,2,2)
s1.restitution=1
s1.friction=0
aa.position=vec3(0,0,0)
aa:add(craft.shape.sphere,size)
aa.model = craft.model.icosphere(size,2)
aa.material = craft.material("Materials:Specular")
aa.material.diffuse=color(255)
c=aa:add(craft.camera, 120, 0, 10, false)
else
c=nil
aa:destroy()
aa=nil
end
end
function createObjects()
for z=1,100 do
a=scene:entity()
s1=a:add(craft.rigidbody,DYNAMIC)
s1.linearVelocity=vec3(2,2,2)
s1.restitution=1
s1.friction=0
a.position=vec3(0,0,0)
a:add(craft.shape.sphere,size)
a.model = craft.model.icosphere(size,2)
a.material = craft.material("Materials:Specular")
a.material.diffuse=color(255,0,0)
end
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
if c then
c.entity.eulerAngles=vec3(angX,angY,angZ)
end
end