@RonJeffries Heres an example to show sleeping allowed and apply force. The apply force seems to work the way it should. The sleeping allowed also seems to work the way it should. The problem is the awake variable. It shows awake if it’s awake, sleeping when it’s sleeping, but it doesn’t change from sleeping to awake when it should. Run the code. Tap or hold the screen above the middle to apply an upward force. When the falling ball is allowed to rest on the fixed ball for about 2 seconds, it will sleep. Applying a force will not move it. Tap the screen below the middle and sleeping allowed is set to false, but the awake variable will still show sleeping even though tapping above the middle will apply force to move the ball.
viewer.mode=FULLSCREEN
function setup()
fill(0,0,255)
scene = craft.scene()
skyMaterial=scene.sky.material
skyMaterial.sky=color(0, 62, 255, 255)
skyMaterial.horizon=color(99, 255, 0, 255)
scene.surotation=quat.eulerAngles(20,45,-30)
v=scene.camera:add(OrbitViewer, vec3(0,0,0), 60, 0, 1000)
a=scene:entity()
s1=a:add(craft.rigidbody,DYNAMIC)
s1.sleepingAllowed=true
a.position=vec3(0,20,0)
a:add(craft.shape.sphere,1)
a.model = craft.model.icosphere(1,2)
a.material = craft.material(asset.builtin.Materials.Specular)
a.material.diffuse=color(255,0,0)
b=scene:entity()
s2=b:add(craft.rigidbody,STATIC)
b.position=vec3(0,-15,0)
b:add(craft.shape.sphere,1)
b.model = craft.model.icosphere(1,2)
b.material = craft.material(asset.builtin.Materials.Specular)
b.material.diffuse=color(255,0,0)
end
function draw()
update(DeltaTime)
scene:draw()
a.material.diffuse=color(255,0,0)
if apply then
s1:applyForce(vec3(0,20,0))
a.material.diffuse=color(0,0,255)
end
if s1.awake==false then
text("sleeping",WIDTH/2,HEIGHT/2)
else
text("awake",WIDTH/2,HEIGHT/2)
end
text("tap or hold screen to apply an up force ",WIDTH/2,HEIGHT/2+50)
end
function update(dt)
scene:update(dt)
end
function touched(t)
if t.state==BEGAN then
if t.y<HEIGHT/4 then
s1.sleepingAllowed=false
else
apply=true
end
end
if t.state==ENDED then
apply=false
end
end