Problem with the rotation of camera in third person

I am currently creating a third person game where the character can manipulates gravity like in gravity rush, so you can walk in every surfaces where you aim like in the ps vita game. To do that I use a ray to know the normal of the surface where the player aim, so I change the rotation of the character, taking in acount that normal, and apply force to its rigidbody in that direction.

The problem is the rotation of the camera around the player in Y axis when you are in any surface different from the ground, because normally the camera rotate around the y axis , but when you change of surface it is not the same axis to rotate the camera, for example and inclined plane where the normal of the player is for example (0.6,0.3,0.7) so the camera has to rotate taking in account the normal or the transform.up of the character. In adition, when the character is in a new surface the camera rotates with him, so both have the same rotation. Maybe I don’t explain properly, sorry for that

I think that I have to use a cross product of vectors but I don’t get the right form, so I need a little help.The code that I use for the rotation of the camera around Y axis is:


This code logically only works currently in the Y axis, so I have to modify it to work in any surfaces.

Thanks in advance.

We need to see more of your code for a exact answer, but here are three approaches:

Use Quaternion.AngleAxis() for your rotation, and use transform.up for the axis.

Use an empty game object as a parent, and assign transform.localRotation for the rotation. You would rotate the parent game object. The child will always have the same local relationship to the parent, so the rotation will work.

If you are simply rotating around, you can use Transform.Rotate(). The default usage is a local rotation, so 'transform.Rotate(0,someDelta,0), will rotate around the correct axis.