#### Topic: How to apply a gravitational force to an object?

How to apply a gravitational force to an object? i want to make a sphere and the player walk 360 around it?

#### Re: How to apply a gravitational force to an object?

well, you can first set the gravity to zero with setGravity :
http://wiki.maratis3d.org/index.php?title=SetGravity

and then at each frame add a central force with a vector going from the object to the center of the sphere.
with addCentralForce : http://wiki.maratis3d.org/index.php?tit … ntralForce

#### Re: How to apply a gravitational force to an object?

This is what i have but cant get it to work.

-- get objects
player = getObject("player")
earth= getObject("earth")

-- scene update
function onSceneUpdate()

gravity = {0, 0, 0}
setGravity(gravity) -- set current scene gravity

end

end

#### Re: How to apply a gravitational force to an object?

you need a direction vector, in your code it's all zero.

``````-- get objects
player = getObject("player")
earth = getObject("earth")

setGravity({0, 0, 0}) -- set current scene gravity to zero

-- scene update
function onSceneUpdate()

vec = normalize(getPosition(earth) - getPosition(player)) * g

end``````

#### Re: How to apply a gravitational force to an object?

but be sure the origin of hearth and player are centered in the mesh

#### Re: How to apply a gravitational force to an object?

Thanks very much anael. this help me understand vectors better.

#### Re: How to apply a gravitational force to an object?

It still falls off the side of the earth tho? how do i make the gravity flip?

#### Re: How to apply a gravitational force to an object?

Heres the project:  https://drive.google.com/folderview?id= … sp=sharing

#### Re: How to apply a gravitational force to an object?

1 - name your objects : "earth" and "player"
2 - import the script in the scene :
http://wiki.maratis3d.org/index.php?tit … to_objects