@dave1707, I tried to add your following code to the healthbar code, and it didn’t seem to work. I’ve been messing around with everything but nothing works. Could you show me how to use the following code that you wrote, and make it so that works???
Here’s the code:
viewer.mode=FULLSCREEN
function setup()
tab={}
assert(OrbitViewer, "Please include Cameras as a dependency")
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)
v=scene.camera:add(OrbitViewer, vec3(0,0,0), 100, 0, 200)
v.rx,v.ry=20,20
createRect()
for z=1,5 do
s1=createSphere(0,30,0,1)
end
for z=1,5 do
table.insert(tab,createSphere(math.random(-10,10),math.random(20,35),math.random(-10,10),0))
end
end
function draw()
update(DeltaTime)
scene:draw()
text("Drag your finger on the screen to rotate the cube",WIDTH/2,HEIGHT-100)
if follow then
for z=#tab,1,-1 do
v1=s1.sphere1.position-tab[z].sphere1.position
tab[z].ss.linearVelocity=v1
end
end
end
function update(dt)
scene:update(dt)
end
function touched(t)
if t.state==BEGAN then
follow=not follow
end
end
function createRect()
diff=8
c1=scene:entity()
w=c1:add(craft.rigidbody,STATIC)
w.restitution=.6
c1.position=vec3(0,-10,0)
c1.model = craft.model.cube(vec3(25,10,10))
c1.model:position(5,-5,diff,5)
c1.model:position(18,-5,diff,5)
c1.model:position(10,-5,diff,5)
c1.model:position(9,-5,diff,-5)
c1.model:position(14,-5,diff,-5)
c1.model:position(19,-5,diff,-5)
c1:add(craft.shape.model,c1.model)
c1.material = craft.material(asset.builtin.Materials.Standard)
c1.material.map = readImage(asset.builtin.Surfaces.Basic_Bricks_AO)
end
function createSphere(x,y,z,c)
local sphere1=scene:entity()
local s=sphere1:add(craft.rigidbody,DYNAMIC)
s.restitution=1.5
sphere1.position=vec3(x,y,z)
sphere1.model = craft.model.icosphere(.5,5)
sphere1:add(craft.shape.sphere,.5)
sphere1.material = craft.material(asset.builtin.Materials.Specular)
if c==1 then
sphere1.material.diffuse=color(0,0,255)
else
sphere1.material.diffuse=color(255,0,0)
end
return({sphere1=sphere1,ss=s})
end