I'm making a game in which the player controlls a ball. (Wow, such originality^^) It's a 3rd person game so the camera is slightly above and behind it. The ball is being controlled via WASD. Now the tricky part is, I want this to work totally independent from the worldaxis so or example even upside down. So in my PlayerControllerScript I have an array of three vectors which represent the new X,Y and Z axis of my ball. The X axis always points in the direction the sphere is moving. The Y axis is calculated by the forces influencing the body. So if the gforces on the body are strong enough, for example while rolling along a craterslope, my Y axis is going to be horizontal. The Z axis is always orthogonal to the firs two.
So much for the explanation. So the camera is always being offset according to those new axis' and then pointed in direction of the gameobject using this line:
T.rotation = Quaternion.LookRotation (TargetTrans.position - T.position);
T being the Camera's transform. I don't really understand this line but it works. My problem is, that this makes the camera always parallel to the horizon, but I want the camera to tilt with the objects movement. So when I'm rolling in circles on a craterslope it should not be parallel to the horizon but to the slope. I tried to Rotate the Transform of the camera around the calculated X axis like so:
T.Rotate(PlayerScript.Orientation , Vector3.Angle(Vector3.ProjectOnPlane( Physics.gravity,PlayerScript.Orientation) ,OtherScript.Orientation) );
Notice that I'm taking the angle between my calculated Y axis and the gravity beeing projected onto the YZ Plane of y calculated orientation. Like this I avoid unwanted tilting, for example when moving straight up the crater slope away from the center. However this line doesn't change anything visually. What's wrong? It's not because the rotation is changed right afterwards with the first command I gave, because the Rotate command comes after it.
I'm starting to realize rotation is a lot more complicated than I thought and eventhough this has to be a very common problem in for all peple who develop games with planes, I couldn't find anything. :(
Help me please... Thanks in advance.
I also realize how hard this even is to explain so let me know if something is not clear.