hi there!
is it possible to disable the gravity for certain objects?
i'm creating an astrolander clone with spaceships (affected by gravity) shooting missiles, which should be agravic.
thanks in advance
No, you need to turn off gravity and then apply it manually yourself (using ApplyForce and GetMass) to the objects in question.
Alternatively, if you are using the SVN HEAD version, then the ConstantAccelController might be a slightly easier way to achieve the same thing.
or i'll just add an boolean value to a body. and with one other line modification... et voilà
open source rocks 😀
Personally I think it would be a useful feature to turn off world gravity for certain objects like bullets and other things that you want to travel in a straight line.
An other way that I've used (I only wanted one object with no gravity) was to apply a force opposite to the gravity before each step.
Technically you could do it that way too, but I am used to calling this kind of approach a "cheap fix". Why add a gravity and then nullify it by applying an opposite gravity when you can achieve the same effect by not applying any gravity in the first place? One approach would be to implement your own gravity handler that applies gravity to only certain objects, but that would pretty much nullify the point of the world gravity. I see the world gravity as some way of specifying a default gravity to objects that are supposed to react to gravity. The world gravity is automatically applied unless an object should obey some different gravity (in that case gravity gets overridden). If you put "gravity zones" throughout your levels, you might achieve something similar to what has been done in Prey.
I think the world gravity is made mostly because it's an easy thing to do in a physics engine.
Most games will make use of a constant gravity value, and the physics engine can just process this force for every object in it's loop. So it's mainly that a default gravity makes sense for the engine, not that it makes sense for every game.
Just a minor point, this like many properties would be really useful if applied to a body not a bodydef so you can toggle it in code very easily. Am I missing something as to why bodyDef is the place for all these things?