Disable gravity in some physic objects

There is any way to have gravity in some objects and disable it in others? I’m talking about physic behaviour.

1 Like

Yes you can,
You just need to set the conditions you want,
For exemple you want your object to have physic when mouse over the object and other object that are not over disable the gravity, so you do a condition.
“if mouse over the object, make the object dynamic”
And you can make the object static, if it’s not over by your mouse
“if mouse not over the object, make the object static”
Here is the action: prntscr.com/j3e30g
And so only object that are over and have gravity behavior would have gravity

Taht’s not disable gravity. Static objects can’t move.

In HTML5 you can use a single line of code to disable the gravity for a specific instance:
At the beginning of the scene (or when you want to disable the gravity) add a JS sub-event, edit the JS event to pass your object as a list parameter and paste the following code:

objects[0].getBehavior("Physics")._box2DBody.SetGravityScale(0);

Two things to note: It assumes the behavior is named “Physics”, you can check this in the object properties panel. Also it assumes there is at least one instance of the object in the scene, otherwise your game will crash, if there is a chance to not have instances in the scene add a check before (I recommend to use it anyway):

if(objects.length > 0){ objects[0].getBehavior("Physics")._box2DBody.SetGravityScale(0); }

It was my result:
Floating.gif

Impossible to do in native right now :frowning:

1 Like