I’m a newbie and am trying to figure out physics bodies. I would think that when I create one of these, it would sit still until told to move but it wanders around. The code below shows what I mean. It just tracks the Y position of the body. Is there some force involved by default?
function setup()
Ans1Body = physics.body(CIRCLE, 100)
Ans1Body.type = DYNAMIC
Ans1Body.x = 500
Ans1Body.y = 500
end
function draw()
background(40, 40, 50)
text (string.format (“Ans1Body.y = %d”, Ans1Body.y), 200, HEIGHT - 100)
end
function setup()
Ans1Body = physics.body(CIRCLE, 100)
Ans1Body.type = DYNAMIC
Ans1Body.x = 500
Ans1Body.y = 500
end
function draw()
background(40, 40, 50)
text(string.format ("Ans1Body.y = %d", Ans1Body.y), 200, HEIGHT - 100)
end
Also, it could be just text("Ans1Body.y = " .. Ans1Body.y), 200, HEIGHT - 100), couldn’t it?
Physics bodies have gravity, if that’s what you mean. You can control it with physics.gravity(). (physics.gravity(Gravity) also makes physics bodies fall with the iPad’s gravity sensor.)
gravityScale fixed the problem. I had read the description of that parameter but interpreted it as meaning that, if set to 0, gravity wouldn’t affect the object. I should have tested.
The code looked OK when I pasted it in but reformatted when the message was posted. Is there a trick for doing this?