anti gravity

I have an underwater game which has some fish swimming around.  However, when I add some crabs I wanted to add a little gravity so that they stay on the bottom of the tank.  When I do this everything gets dragged down.  Even bubbles which I want to float up.  I realize I can create a run time loop that constantly fights against the force of gravity but shouldn’t this be as simple as setting the density to 0 or even -1?  If an object has no mass shouldn’t gravity have no effect?   In a perfect world I would set gravity to 1 and then set the density to 0 for objects that I don’t want effected.   Isn’t this how it is supposed to work?  What am I missing?  

L

To change the gravity of physics, use this:

physics.setGravity(gravity in x direction, gravity in y direction)

gravity in x direction = this will change the gravity acting in x direction

gravity in y direction = this will change the gravity acting in y direction

To keep no gravity in your game:

physics.setGravity(0, 0)

Use the gravityScale property to adjust the gravity on a single body.

See this guide:

https://docs.coronalabs.com/api/type/Body/gravityScale.html

Setting the gravity globally would not work, as I assume he wants to have negative gravity, so objects can flow to the top.

Use the property .gravityScale instead for your physic objects. You may set it to any positive or negative value and it is multiplied with the global gravity. (so objects with gravityScale = -1 will fall in the opposite direction and those with gravityScale = 0 aren’t effected by gravity at all)

thanks,  I didn’t know about gravityScale.   I will give it a try.  thanks bunches. 

gravityScale worked perfectly. :slight_smile:

i need idea  to anti gravity for one object and  gravity for anther?
anti gravity for one object only ?? plz help me

Hi @k117,

The .gravityScale property can be both positive and negative, so you can use it to change gravity on every object as needed. For example, if you set it to -1.0, and normal “world” gravity is pushing objects down, the object with -1.0 will actually float upwards.

https://docs.coronalabs.com/api/type/Body/gravityScale.html

Hope this helps,

Brent

To change the gravity of physics, use this:

physics.setGravity(gravity in x direction, gravity in y direction)

gravity in x direction = this will change the gravity acting in x direction

gravity in y direction = this will change the gravity acting in y direction

To keep no gravity in your game:

physics.setGravity(0, 0)

Use the gravityScale property to adjust the gravity on a single body.

See this guide:

https://docs.coronalabs.com/api/type/Body/gravityScale.html

Setting the gravity globally would not work, as I assume he wants to have negative gravity, so objects can flow to the top.

Use the property .gravityScale instead for your physic objects. You may set it to any positive or negative value and it is multiplied with the global gravity. (so objects with gravityScale = -1 will fall in the opposite direction and those with gravityScale = 0 aren’t effected by gravity at all)

thanks,  I didn’t know about gravityScale.   I will give it a try.  thanks bunches. 

gravityScale worked perfectly. :slight_smile:

i need idea  to anti gravity for one object and  gravity for anther?
anti gravity for one object only ?? plz help me

Hi @k117,

The .gravityScale property can be both positive and negative, so you can use it to change gravity on every object as needed. For example, if you set it to -1.0, and normal “world” gravity is pushing objects down, the object with -1.0 will actually float upwards.

https://docs.coronalabs.com/api/type/Body/gravityScale.html

Hope this helps,

Brent