n5ro / aframe-physics-system

Physics system for A-Frame VR, built on CANNON.js.
https://n5ro.github.io/aframe-physics-system/
MIT License
505 stars 136 forks source link

question : floating bubble physic #163

Closed arthurmougin closed 3 years ago

arthurmougin commented 3 years ago

Hello :)

I want to create floating entities that may have a negative mass and are slowed by "air friction" without messing with the gravity value. Do you know how I could do that with your physic system?

thank you in advance!

(right now I have made the gravity value very low and positive but it affects non-bubble object too)

n5ro commented 3 years ago

By default the Aframe Physics System has up until now relied upon the Cannon js library for physics, but it is also possible to use the Ammo js library with the Aframe Physics system.

Ammo js is even more broadly used in the video game industry for physics in games (Ammo is known as Bullet in the game industry; "ammo.js is a direct port of the Bullet physics engine to JavaScript, using Emscripten. The source code is translated directly to JavaScript, without human rewriting, so functionality should be identical to the original Bullet." )

I mention these two physics engines because essentially that means that anything you see in any other game engine, in terms of game physics, is technically possible to do also with the Aframe Physics System, and to learn more about the things you can do with the Aframe Physics System you should consider reading all the documentation on the Cannon js library, and alternatively or also the entire Ammo js library.

So read this to learn more about what you can do with Cannon http://schteppe.github.io/cannon.js/ https://github.com/schteppe/cannon.js When you are researching the potential capabilities of the Aframe Physics System you can also look at the Cannon js library examples page for examples of things that can be done with the Aframe Physics System. https://github.com/schteppe/cannon.js/tree/master/examples

Read this to learn more about what you can do with ammo js. Ammo js is probably the future of the Aframe Physics System. So it might a more interesting place to start. https://github.com/kripken/ammo.js/ Check out the demos on that page in the readme file.

To summarize: Pretty much all the game physics, that you can find all the mainstream videos games, including stuff made with the mainstream game engines such as Unity or Unreal Engine (in terms of game physics) is possible with the Aframe Physics System.

Specifically to your air-friction question. A negative mass is not going to cause entities to rise to my knowledge. I believe that in order to make an object rise, it's not just about lowering gravity or reducing object mass, you need an actual force that pushes or pulls the object upwards, I guess a negative mass would work if there was an atmosphere simulation that was pushing objects of lighter mass upwards, but there is no air in VR, no simulated air I mean, so that might be why simply lowering gravity or reducing mass, or having negative mass won't make anything float.

You are going to need a force to push your entities upwards. Unfortunately I am not ready today with a more direct answer to that direct problem it will require some further research into the physics game engine libraries, but perhaps that will be a useful pointer for you to think about what you might need next to achieve your goal.

n5ro commented 3 years ago

You want to either applyImpulse or applyForce to your floating entities. the difference between applyImpulse and applyForce is timing, apply impulse is like a one time event, apply force has a longer duration like gravity https://github.com/chandlerprall/Physijs/issues/19