- Home /
Mouse Orbit - Camera Up Vector
Hi there,
I'm trying to move my character over places with different gravity normal’s (similar to mario galaxy). I'm using a basic mouse orbit script to control the camera:
Code:
velocityX += (float)(Input.GetAxis("Mouse X") * xSpeed * 0.2f);
velocityY -= (float)(Input.GetAxis("Mouse Y") * ySpeed * 0.2f);
transform.rotation = Quaternion.Euler(velocityY, velocityX, 0);
transform.position = (Quaternion.Euler(velocityY, velocityX, 0)) * new Vector3(0.0f, 0.0f, -distance) + target.transform.position;
The problem is that this mouse orbit only works well if the gravity's normal is (0,-1,0), for any different gravity then the min/max don't seem to work + the rotation around the axis is obviously not done properly either.
I tried to modify the camera up normal using transform.lookat(player, gravityNormal). The camera seems to face the proper direction but the errors mentioned above happen.
Do you have any idea how this can be solved?
Thanks very much in advance!
Comment