How to create a gravity field?


#1

I am trying to create a gravity field (for my planet) that pull any object that entered the field toward the planet .
Have tried many ways. Not working so far.

Here is the link to my project
https://playcanvas.com/project/344933/overview/starter-project

Any help is appreciated.


#2

If the other object is inside the field, subtract their positions - this will give you a direction towards the planet. From there it’s up to you what you do with it.

You could then normalize it (make each x/y/z a value between -1 and 1) and multiply it by a speed.

            var gravity = new pc.Vec3();
            gravity = this.planet.getPosition().sub(this.entity.getPosition());
            gravity.normalize().scale(9);
            this.entity.rigidbody.applyForce(gravity);

For testing if it’s inside the field I use the trigger enter and trigger leave events to set a boolean in your Force script. Unfortunately I don’t think there is a more direct way like triggerstay - but you could also probably solve this by doing a distance check yourself.

https://playcanvas.com/project/346041/overview/gravityfield


#3

Thanks for the answer. :smile:


#4

The way we think about gravity is wrong.
We know this because we cannot create or manipulate it as we understand gravity today. The way gravity is thought of today doesn’t fit within the scientific model.
Here is how it does:

Gravity is created by the principle of displacement. Matter displaces the energy of the universe, what we are calling dark energy, or space itself. This displacement is what we know as gravity. Gravity is a push not a pull.

For your gravity model to work just treat the planet as if it is submerged in fluidic-energy. The energy is displaced by the mass and pushes on all sides equally but it also saturates the matter too holding it together.

Energy and matter are interchangeable. We know this from E=Mc2. Thus energy solidifies into more solid forms, and solids desolitify back into energy. Thus all the universe exists in this never ending state of change, and in a cycle that keeps it existing the way it does.

Hope this helps clear things up and gets people thinking the right way so we can actually create and manipulate gravity and create products which employ it for mankind’s benefit.

All things must have a medium in order to exist and function. Dark energy is that medium. It also allows light to travel. Thus the speed of light is dependent on its medium. Thus if we control lights medium we can travel faster than light.

96% of the universe is dark energy. We should strive to understand it first because it is the foudation for everything else.