It looks like you're new here. If you want to get involved, click one of these buttons!
Here's my example. I expect that when I press the applyForce button, the box should go flying. It doesn't move at all.
What am I missing? Thanks!
-- ApplyForce?
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("Force", applyForce)
end
function applyForce()
BoxBody:applyForce(vec3(100,100,100))
end
function update(dt)
scene:update(dt)
end
-- Called automatically by codea
function draw()
update(DeltaTime)
scene:draw()
end
function createBox()
local box = scene:entity()
local body = box:add(craft.rigidbody, DYNAMIC, 1) -- mass
body.restitution = 0.8
BoxBody = body
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)
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
Comments
Curiously, once in a while it moves. Very infrequently.
@RonJeffries When I tap on Force, the box jumps to the left. If I uncomment the physics.gravity line, then it continues in a up/left direction. So it appears to work for me.
Weird. Doesn't work on either of my iPads. Once in a long while it moves.
@John any idea what's up?
@RonJeffries I deleted your example on my iPad and loaded it again. It still works. With gravity, it jumps to the left on the floor. Without gravity, it continues to move up and left. I’ll try it on my other iPads.
on my fastest ipad it moved very occasionally. even putting huge numbers in the vector does nothing.
ah! if i tap while it is still settling, it responds. if i wait till it's dead stopped, it doesn't go. it's as if physics stops running if nothing is going on.
It works on my iPad Air 3, iPad Air 4 and iPad Pro 1 and iPhone 8 SE.
Tried it on my iPad Air 1 and it worked.
does it work even if you wait a long time, letting the falling one completely settle and then press the button?
@RonJeffries Try adding this.
That didn’t seem to work. If I wait 2 minutes, the Force button doesn’t work. I thought for sure the sleepingAllowed= false would work.
PS. Just waiting about 10 sec and it doesn’t work.
body.sleepingAllowed
makes it move almost every time. I wonder what sleeping is.it's body, not box tho.
@RonJeffries That was my mistake. The sleepingAllowed should be applied to the rigidbody variable, not the entity variable.
interestingly even with that in place it doesn't always work. I checked to be sure physics wasn't paused. it wasn't. i hope @John or @Simeon can take a look.
@RonJeffries I waited 3 minutes and it still worked.
it usually works for me, but not always. if i'm to document it, i'm like to know what's up.
with sleep permission false, i display awake or asleep in draw depending on BixBody.awake and it is always false, i.e. not awake.
Very weird.
@RonJeffries That's weird, it's supposed to wake up the rigidbody automatically whenever you call addForce / addTorque, must be a bug
I found that even if I say
body.awake = true
, right before applying force, it still doesn't move sometimes. Does awake get cleared when it thinks an object is still?@RonJeffries I think the awake variable is read only. That’s used to check if the object is sleeping or awake. The sleepingAllowed variable is what gets set. Should set that variable to true then check the awake variable and see what it shows.
PS. I tried it and when I set sleepingAllowed to false, awake is false. If set to true, awake is true.
Add this to draw(), you can watch it change from true to false in a few seconds.
you'd think that sleepingAllowed = false would set awake = true.
Is it really backward?
I've seen awake change. Mostly it stays off even when the thing does respond. And nothing I do makes it respond every time. I think there's a bug in there somewhere.
I guess awake could be just a status that is written but not read inside. If so, I'd like to know what I have to do to wake the thing up. Right now I'm afraid to document the force stuff because I can't explain it.
This somewhat convoluted version uses
sleepAllowed=false
, which does seem to work backward. The force button applies an upward force on the next draw cycle. if you set force = n, it'll apply force that many times, in the next n draw cycles.The wake button sets the
body.awake
to true and force to 1. That usually results in the object waking up and moving. but not always.the awake/asleep status is displayed near the bottom of the screen.