Topic: Walk 360 around the surface of a sphere

So i want to walk 360 (anywhere) around the surface of a sphere without falling off how do i achieve this?

Here a diagram of what i want to do the cube is the FPS player and the sphere is the earth:
http://imgur.com/HHU1TeL

Last edited by blend (2014-07-05 17:43:53)

Re: Walk 360 around the surface of a sphere

you can start by setting the gravity every frame to this vector : normalize(sphereCenter - playerPosition)*0.98

Re: Walk 360 around the surface of a sphere

how do i get the player position and center of sphere? I don't really understand

Last edited by blend (2014-07-05 19:28:25)

Re: Walk 360 around the surface of a sphere

getPosition :
http://wiki.maratis3d.org/index.php?title=GetPosition

Re: Walk 360 around the surface of a sphere

This is the code i still cant figure it out? It's just the sponza tutorial with a sphere in it

Player = getObject("Player")
Head = getObject("Head")
room = getObject("room")
sphere = getObject("sphere")

dx = 0.0
dy = 0.0

centerCursor()
mx = getAxis("MOUSE_X")
my = getAxis("MOUSE_Y")

-- scene update
function onSceneUpdate()

    playerPosition = getPosition(Player)
    vec = normalize(sphereCenter - playerPosition)*0.98)

    -- rotate Player (X mouse)
    rotate(Player, {0, 0, -1}, dx*100)
    
    -- rotate Head (Y mouse)
    rotate(Head, {-1, 0, 0}, dy*100, "local")    
    rotation = getRotation(Head)
    if rotation[1] > 90 then
        rotation[1] = 90
    elseif rotation[1] < -90 then
        rotation[1] = -90
    end

    setRotation(Head, rotation)
    
    -- move    
    if isKeyPressed("W") then
        addCentralForce(Player, {0, 6, 0}, "local")
    end
    
    if isKeyPressed("S") then
        addCentralForce(Player, {0, -6, 0}, "local")
    end
    
    if isKeyPressed("A") then
        addCentralForce(Player, {-3, 0, 0}, "local")
    end

    if isKeyPressed("D") then
        addCentralForce(Player, {3, 0, 0}, "local")
    end    
    
    if isKeyPressed("SPACE") then
        addCentralForce(Player, {0, 0, 3}, "local")
    end    
    
    -- get mouse direction
    dx = getAxis("MOUSE_X") - mx
    dy = getAxis("MOUSE_Y") - my

    -- center cursor
    centerCursor()
    hideCursor()
    gravity = {0, 0, -90}
    
    mx = getAxis("MOUSE_X")
    my = getAxis("MOUSE_Y")    
    
end
(

Last edited by blend (2014-07-11 22:19:09)

Re: Walk 360 around the surface of a sphere

well i guess nobody knows

Re: Walk 360 around the surface of a sphere

You just need to get your hands into vector mathematics,
there is some good introductions online, I found this : http://www.matrix44.net/cms/notes/openg … th-vectors

Because your problem is just about mathematics, your need to understand how to handle vectors in a 3d world, then it will be a piece of cake.

There is two ways to solve your problem :

1 : use physics and modify the gravity vector like stated above depending on the player position and the planet center

2 : move the player yourself using vector and matrix math :
     - get the player position
     - move the player position orthogonally to the planet radius
     - keep the player to the surface : force the distance of the vector |playerPos - planetCenter| to be always equal to the planet radius