• Hello [name]! Thanks for joining the GMC. Before making any posts in the Tech Support forum, can we suggest you read the forum rules? These are simple guidelines that we ask you to follow so that you can get the best help possible for your issue.

Question - Code negative density behaves as it was zero density

Liquid

Member
How could i create an object that is lighter than air and will float upwards ?
i thought i set the density to negative 0.7 ... but it will be treated as 0 density and stuck at the place...

workaround would be aplying a force every frame against the gravity .. i would need to know the force aplied by the normal gravity first..but that changes with size...
big problem would be frame dependency than on this workaround.... depending on frame rate it would behave differently

but is there a normal way to use negative densities and make it work ??

thanks
 
Last edited:

Liquid

Member
could i somehow create 2 different gravities ? collision group 1 going up and collision group 2 gravity goind down ??
 
noone has a clue ? noone sees a need for negative gravity ?
Gravity can be set for every object. Simply set the gravity direction up and set the gravity to a low number. It will only affect that object. You can also set it per instance if you need. Density is not the property you are looking for. Density is a function of the size of the sprite as compared to its density. So a 1*1 sprite with a density of 1 would have a higher density than a 2*2 sprite with a density of 1. Density can effect how the object reacts to forces so you are likely going to want a low density. However I have no idea how negative density functions - it may not I will have to test.
 

Liquid

Member
negative density doesnt exist in real world, and means that something is lighter than the surrounding "no game objects" ....
lighter than the free room without objects. GM2 treates negative density as if its positive. -2 becomes +2.

finally i worked out the problem :
activating the "enable physics" checkbox in room editor will overwrite all useage of object member variable "gravity_direction" and "gravity".
because i activated that both were ignored and had no influence !! with turning off the physics in roomeditor i was able to set different gravities for different objetcs.
Thanks 2 "The Video Gamester"

Problem is : i need this to work in physics room ... not in non physics room
using member var gravity_direction will not allow collisions to happen..as soon as i use physics_world_create(1/32) it wont work again !
 
Last edited:

chirpy

Member
So you actually meant "gravity", not "density" in this thread's title right?

I may be wrong, but I believe in gms2 you'll have set gravity to 0 in physics rooms, and simulate your own gravity with desired direction.
 

Liquid

Member
So you actually meant "gravity", not "density" in this thread's title right?

I may be wrong, but I believe in gms2 you'll have set gravity to 0 in physics rooms, and simulate your own gravity with desired direction.
gravity is the cause of the force to happen to objects with mass.
density is the ratio how much mass is packed into a decent volume.

i want a ballon to rise upwards in the opposite direction of normal gravity, therefore i need a density of the ballon less than the surrounding "air".
Because we have no "air" in the room and no surrounding "air" objects in the simulation i thought it would be solveable with individual (only for the ballon object) negative gravity OR negative density. Mathematical both would work
but both are not possable in the GM2 language.

as soon as i enable "physics" in a room the individual gravity_direction will be ignored as well as the individual gravity.
you could have the physics simulated with "enable physics" ( equals the physics_world_create function) XOr the individual treatment with gravity and gravity_direction.
 

mproxima

Member
Did anybody solve this? I get what you are saying, I was thinking that if I set Density to -something the object would float but it behave exactly as Density = 0.
 

mproxima

Member
Ok I found out that if you set the object you want to float as Kinematic and then give it a -phy_linear_velocity_y it start to float. A bit weird upun ceiling collision though
 
Top