Physics request....

A way to turn off gravity for individual bodies would be extremely useful for me and (judging by the forums) a lot of other people too.

During the development of my game I’ve encountered a number of issues where I have to fight with kinematic and dynamic and static objects to keep things moving correctly, all of which would have been completely avoided by having a “respondsToGravity=false” flag.

I know it’s not too difficult to implement in box2d; I found some source code in a quick google search where a guy added exactly that feature to his box2d application by adding something like three lines of code inside one file, to prevent the application of the gravity force to the object.

So, please do it! :slight_smile:

[import]uid: 53578 topic_id: 9028 reply_id: 309028[/import]

+1 [import]uid: 52627 topic_id: 9028 reply_id: 37385[/import]

+1 [import]uid: 12088 topic_id: 9028 reply_id: 37388[/import]

instead of setting respondsToGravity=false and after some time again respondsToGravity=true

u ccan use obj.bodyType = “static” or “kine…” and after some time obj.bodyType = “dynamic”

:slight_smile: [import]uid: 12482 topic_id: 9028 reply_id: 37403[/import]

The problem with that is that kinematic objects don’t collide with static or kinematic objects.

So, if you have a game with a spaceship flying through a level, and you set your ship to kinematic so it ‘floats’, it won’t ever collide with the static terrain in your level.

Having your player character as dynamic but without gravity would make a number of different types of games a *lot* easier to write.

Another example is bullets; if you have your ship fire physics bullets, gravity is going to make them arc downwards. IF you make the bullets kinematic, they’ll fire straight, but again there will be problems with them registering collisions with terrain and other kinematic objects (such as ships that need to float…)

[import]uid: 53578 topic_id: 9028 reply_id: 37406[/import]

ohhh got that

use linearDamping example,

[lua]local physics = require “physics”
physics.start()
physics.setGravity(0,10)

local obj1 =display.newRect(0,0,100,100)
local obj2 =display.newRect(110,0,100,100)

physics.addBody(obj1)
physics.addBody(obj2)

local function callME()
obj1.linearDamping = 100
end
timer.performWithDelay(1000,callME)[/lua]

:slight_smile: [import]uid: 12482 topic_id: 9028 reply_id: 37408[/import]

linearDamping is applied to both x and y direction, so it freezes, but not float . [import]uid: 12088 topic_id: 9028 reply_id: 37437[/import]

Yeah, linear damping doesn’t help at all…
Well, I mean, it does, but then if something hits your object it’s like it hit a brick wall.

There are ways to kinda simulate it; like adding a constant up-force, but there’s no way to do it “right”.

With access to the box2d C code, making a dynamic body that doesn’t see gravity is a matter of about 3 lines of code…

Oh well, I guess there has to be some limitations somewhere! Ansca can’t make it TOO easy for us :wink:
[import]uid: 53578 topic_id: 9028 reply_id: 37452[/import]