Jump to content
  • Advertisement

Rotation in a sphere

Recommended Posts

I would like the player to be walking inside of a sphere, so the controls of the camera and the movement are relative to the position in the sphere. I already imlemented the gravity but I am having trouble with the rotation and controls of the camera.


Share this post

Link to post
Share on other sites

(Disclaimer: just woke up)

Looks like what you want is the tangent of the circle at the point where the player is.

This should be just orthogonal to the gravity vector you already have.

Share this post

Link to post
Share on other sites

I'll make the sphere centered at the origin and with radius 1, for simplicity. Your position on the sphere is a unit-length vector, and your forward direction is another unit-length vector which is perpendicular to the position vector. That's the whole state. It's also handy to have a side direction, which can be computed as the cross-product of the other two vectors. You can move by adding a small multiple of the forward direction or the side direction to the current position. You can then renormalize the position (project back to the surface of the sphere, so you don't walk on a tangent) and use the Gram-Schmidt process to adjust the forward and side vectors.

From the position, forward and side vectors, you should have all you need to set up the camera.

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!