Jump to content

Ignore Gravity and Use Collisions only


Recommended Posts

Hi, I am new to Babylon.js and trying out different things which I might need to use in future projects.

I was wondering if there is a way to cancel out gravity from physics so the objects don't float away and stay static and just use the collision aspect of physics where the one mesh wont allow other meshes to pass through it.

I found out that if I set the gravity to zero and the Impostor to PlaneImpostor the meshes stay static in space and I can move them around using pointerevents etc but the meshes dont have any interaction (meshes pass through each other when I drag them). I might have to add callbacks but that would be same as using collision detection without the physics engine

Link to comment
Share on other sites

  • 3 months later...

Following up on this topic, is there a way to have the physics impostor working but not applying the gravity force on some meshes?

For example, to simulate hoovering helicopter at fixed altitude or plane flying forward without falling?

The option


Doesn't make a difference for the physics engine.

When I use


then the mesh doesn't respond to any force anymore and just sits there still, as if I ran the command


same effect (all physics ignored, even applyImpulse and applyForce and setLineairVelocity etc.).

In the desired scenario the steering of the helicopter and/or plane is done by application of force/impulse. And when two planes hit or plane hits helicopter then the physics engine will compute the new velocities and rotations for me. (For even more game excitement, when a rocket or missile hits the airborne unit 🙂 )

Here's a picture to get the idea:


The difference with a motorEnabled solution (for ground driving car like meshes) is that the plane or helicopter doesn't have a ground surface with friction to "roll up the wheels against". It is more like that the plane or helicopter motor/propeller cause upward force that compensate gravity. To lower altitude, the upward force on the object is lowered, and the gain altitude the upward force is increased relative to the gravity.

Hope someone has some experience with physicEngine on this type of flying/floating meshes/gameobjects. 🙂

babylonjs how to keep airborne meshes afloat with gravity physicsEngine.jpg

Edited by QuintusHegie
Added illustration
Link to comment
Share on other sites

You have a few options to choose from.

Every frame, you can set the Y velocity of the physics body to 0.

You can also apply a constant upward force of the same value as the gravity.

Or you can set the gravity to 0, and then apply downward forces to the bodies you need to apply gravity to.

Another thing is to take the wanted position, let's say (14,20,32), and use this to calculate a direction vector based on the current position and the wanted position. Then you apply this vector as your force, to constantly keep the body moving toward the direction. The farther it is from the position, the faster it will go. That behavior can be prevented by scaling the vector by some static value, though.

Link to comment
Share on other sites

Hi Raggar,

Thanks for your ideas.

I like this suggestion the most as it keeps most steering options working forces intact for a flying/floating body:

On 8/19/2018 at 10:52 PM, Raggar said:

You can also apply a constant upward force of the same value as the gravity.

I would then align this 'upward' applyForce vector with the direction of the propeller normal direction in world space. (see picture in my previous post)

Player controls propeller speed and propeller rotation. More propeller power will then result in a higher factor to scale this vector with; lower propeller power lowers this steering factor and thus the downward gravity force slowly starts to win from the (local) updraft force of the drone. Also, when the propellers rotate 30 degrees around horizontal plane for example, the applied force to the main body will be both upward AND sideways hence making the drone fly forwards and some floating as well using the same steering mechanism.

I'll try this approach and let you know if it solved the case.

Take care,


P.S. I'm also curious how Microsoft Flight Arcade http://flightarcade.com/ computed the plane vectors and forces; must have been similar challenge I guess... 🙂


Link to comment
Share on other sites

Short update.

To float or hoover a plane/drone/ufo it works to apply a force on every scene render that negates the gravity force by some factor (e.g. 1 for perfect hoover)

    scene.getPhysicsEngine().gravity.negate().scaleInPlace(damping_factor * speed_throttle),

The damping factor adjusts the speed throttle of the drone (gamepad axis) so that I can setup different drone lifting power (e.g. drones with bigger or smaller propellers).

When you translate the drone local normal vector by some angle around an axis, then you can add forces to the x and z direction as well in order to steer the drone sideways and backward/forward. I haven't worked out those computations at this moment though, because I first wanted to test if I can make a drone mesh float in air by simulation upward propeller force. 🙂


Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...