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?
You are not logged in. Please login or register.
How to apply a gravitational force to an object? i want to make a sphere and the player walk 360 around it?
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
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
addCentralForce(earth, {0, 0, 0}, "local")
end
end
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
g = 0.98 -- your new hand made gravity force
-- scene update
function onSceneUpdate()
vec = normalize(getPosition(earth) - getPosition(player)) * g
addCentralForce(player, vec)
end
but be sure the origin of hearth and player are centered in the mesh
Thanks very much anael. this help me understand vectors better.
It still falls off the side of the earth tho? how do i make the gravity flip?
Heres the project: https://drive.google.com/folderview?id= sp=sharing
1 - name your objects : "earth" and "player"
2 - import the script in the scene :
http://wiki.maratis3d.org/index.php?tit
to_objects
Powered by PunBB, supported by Informer Technologies, Inc.
Currently installed 3 official extensions. Copyright © 2003–2009 PunBB.