With this code in draw, a dropped object shows awake for a while. When it settles, it shows asleep. This seems reasonable.
function draw()
update(DeltaTime)
scene:draw()
if BoxBody.awake then
text("awake", 400,100)
else
text("asleep", 400,100)
end
end
However if we say this in setting up the body:
BoxBody.sleepingAllowed = false
The display now shows “asleep” all the time. From the object’s behavior it seems that it is not asleep, but thinks it is.
I test this with applyTorque and applyForce, neither of which seems to wake up a sleeping object: they probably should. Even when the object is awake, they do not always move the object. I think they probably should.
Below is my full test program:
-- CoCraTu-006
function setup()
scene = craft.scene()
--scene.physics.gravity = vec3(0,0,0)
createFloor()
createBox()
scene.camera:add(OrbitViewer, vec3(0,0,0), 20, 1, 20)
angle = 0
parameter.action("Twist", twist)
end
function twist()
BoxBody:applyTorque(vec3(0,40,0))
end
function update(dt)
scene:update(dt)
end
function draw()
update(DeltaTime)
scene:draw()
if BoxBody.awake then
text("awake", 400,100)
else
text("asleep", 400,100)
end
end
function createBox()
local box = scene:entity()
BoxBody = box:add(craft.rigidbody, DYNAMIC, 1) -- mass
BoxBody.restitution = 0.8
BoxBody.sleepingAllowed = false
box:add(craft.shape.box, vec3(1,1,1))
box.model = craft. model.cube(vec3(1,1,1))
box.material = craft.material(asset.builtin.Materials.Specular)
box.material.map = readImage(asset.builtin.Blocks.Missing)
box.y = 5
return box
end
function createFloor()
local floor = scene:entity()
local body = floor:add(craft.rigidbody, STATIC)
body.restitution = 0.9
floor:add(craft.shape.box, vec3(25, 0.01, 25))
floor.model = craft.model.cube(vec3(25, 0.1, 25))
floor.y = -1.05
floor.material = craft.material(asset.builtin.Materials.Specular)
floor.material.map = readImage(asset.builtin.Blocks.Brick_Grey)
floor.material.offsetRepeat = vec4(0,0,25,25)
return floor
end