I’m trying to do spherical movement while the horizontal and vertical depends on the camera with the camera rotating with the player. I was able to the movement, but when the character reaches the bottom of the sphere, he either spins or gets stuck. I have searched all over with so many different words “Spherical Movement” Planet Movement" “Mario Galaxy Movement” etc. I have tried those answers but they either, aren’t using relative to camera movement, or I end up getting the same result as before. The result I want to get is the second half of this video http://www.youtube.com/watch?v=s-FmZgo9pEg
After completely rewriting the script about 20 times, this is what it looks like now
Player
// Get the up direction
Vector3 up = (transform.position - planet.transform.position);
up.Normalize();
// Rotate the player
Vector3 lookatPoint = Vector3.Cross(transform.right, up);
transform.LookAt(transform.position + lookatPoint, up);
// Camera rotation will be this
camRot = transform.rotation;
// Rotate by Mouse Y
transform.rotation *= Quaternion.AngleAxis(mainCamera.GetComponent<CameraControl>().localRot.eulerAngles.y,Vector3.up);
Camera
// Get the Mouse X and Y movement
_x = (Input.GetAxis("Mouse Y") * ySpeed) * 0.02f;
_y = (Input.GetAxis("Mouse X") * xSpeed) * 0.02f;
localRot.eulerAngles += new Vector3(-_x, _y, 0);
// Limit the Mouse Y movement
if(localRot.eulerAngles.x < 360+yMinLimit){
if(localRot.eulerAngles.x > 180){
localRot = Quaternion.Euler(new Vector3(Mathf.Clamp(localRot.eulerAngles.x-360, yMinLimit, yMaxLimit),localRot.eulerAngles.y,localRot.eulerAngles.z));
} else {
localRot = Quaternion.Euler(new Vector3(ClampAngle (localRot.eulerAngles.x, yMinLimit, yMaxLimit),localRot.eulerAngles.y,localRot.eulerAngles.z));
}
}
// Rotate to match the player orientation
_myTransform.rotation = target.parent.GetComponent<Player>().camRot;
// Rotate by Mouse X and Y
_myTransform.rotation *= Quaternion.AngleAxis(localRot.eulerAngles.y, Vector3.up)
* Quaternion.AngleAxis(localRot.eulerAngles.x,Vector3.right);
// Move to player position
_myTransform.position = target.position - (_myTransform.forward * currentDistance);
I’ve been trying to figure this out for the past week and I just decided to give up and ask here.