WalkOnSphere

=WalkOnSphere.cs=

Author
zombience aka Jason Araujo

Description
WalkOnSphere.cs is intended to allow a first person camera to walk around a sphere and always maintain the appropriate orientation. The script includes raycasting to allow for terrain variation, although it is not designed to handle extreme terrain variation.

WalkOnSphere.cs should be placed on a Camera that is the child of an otherwise empty object. The parent object should be at the same location as the "planet" or sphere that you want to navigate.

WalkOnSphere.cs was adapted from code posted by Unity Answers user Statement in response to a question about spherical movement

Variables
float rotSpeed - the speed for rotating the camera horizontally float moveSpeed - the speed to navigate forward, back, and side to side float rotDamp - how quickly the rotation slows to zero on no input float moveDamp - how quickly the player slows down on no input float jumpheight - how high is a jump? float gravity - how "fast" is a jump? float radius - this will be automatically set by raycast. Transform planet - the object around which the player will walk Transform trans - a direct reference to the player transform for more efficient position updating Transform parent - a reference to the camera parent, in case you want the planet to move, and the player to move with the planet float angle - used for calculating movement float curJumpHeight - used for jumps in progress float jumpTimer - calculating jump progress bool jumping - are we currently jumping? Vector3 direction - used for movement updating Quaternion rotation - used for determining rotation around planet