ibisum wrote:Box2D? Set the gravity for the air object to -0.25 (or some such thing).
- MOAIBox2DBody:applyForce ( MOAIBox2DBody self, number forceX, number forceY [, number pointX, number pointY ] )
-
- MOAIBox2DBody:applyLinearImpulse ( MOAIBox2DBody self, number impulseX, number impulseY [, number pointX, number pointY ] )
-
Oh I didn't know you could set gravity per object.
Am I just not seeing an API reference documentation?
- // Set the gravity scale to zero so this body will float
- bodyDef.gravityScale = 0.0f;
-
- --- starts physics simulation
- -- @param value boolean:optional value not available at the moment
- function RNPhysics.start(value)
- if value ~= nil then
- print("noSleep not available at the moment")
- end
- world = MOAIBox2DWorld.new()
- world:setGravity(0, 10)
- world:start()
- world:setUnitsToMeters(0.06)
- end
- world:setGravity(gravityX,gravityY)
ibisum wrote:Use the second arg of setGravity() to set up your gravity so things either sink or float .. a positive number makes things go up, negative go down. First arg is for horizontal gravitational force, I don't think you'll need that ..
Applying the force? Use a coroutine in your main thread.
- //Box2D v2.2.1 onwards
- body->SetGravityScale(0);//cancel gravity (use -1 to reverse gravity, etc)
skaflux wrote:Can someone confirm what version of BOX2D we are using?
skaflux wrote:I didn't see SetGravityScale() reference on the SDK documentation page.
@Andre: You can try body:setGravityScale(0) to see what happens.
- attempt to call method 'setGravityScale' (a nil value)
-
- MOAISim.openWindow ( "test", 640, 480 )
-
- viewport = MOAIViewport.new ()
- viewport:setSize ( 640, 480 )
- viewport:setScale ( 16, 0 )
-
- layer = MOAILayer2D.new ()
- layer:setViewport ( viewport )
- MOAISim.pushRenderPass ( layer )
-
- -- set up the world and start its simulation
- world = MOAIBox2DWorld.new ()
- world:setGravity ( 0, 0 ) -- Set gravity to zero for floating objects
- world:setUnitsToMeters ( 2 )
- world:start ()
- layer:setBox2DWorld ( world )
-
- -- Add floating body
- floatBody = world:addBody ( MOAIBox2DBody.DYNAMIC )
- floatFixture = floatBody:addRect ( 0.5, -0.5, 1.5, 0.5 )
- floatFixture:setDensity ( 1 )
- floatFixture:setFriction ( 0.3 )
- floatFixture:setFilter ( 0x01 )
- floatBody:resetMassData ()
-
- -- Add dropping body
- dropBody = world:addBody ( MOAIBox2DBody.DYNAMIC )
- dropFixture = dropBody:addRect ( -1.5, -0.5, -0.5, 0.5 )
- dropFixture:setDensity ( 1 )
- dropFixture:setFriction ( 0.3 )
- dropFixture:setFilter ( 0x01 )
- dropBody:resetMassData ()
-
- -- Add a ground body
- groundBody = world:addBody ( MOAIBox2DBody.STATIC )
- groundFixture = groundBody:addRect ( -5, -5, 5, -3 )
-
- -- Co routine to apply force
- mainThread = MOAICoroutine.new ()
- mainThread:run (
- function ()
- while true do
- coroutine.yield()
- -- Apply force every frame to dropping body
- dropBody:applyForce(0, -5, dropBody:getWorldCenter())
- end
- end
- )
-
Users browsing this forum: No registered users and 0 guests