- Home /
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:
transform.rotation=Quaternion.euler(0,mousedegress,0)
This code logically only works currently in the Y axis, so I have to modify it to work in any surfaces.
Thanks in advance.
Answer by robertbu · Oct 06, 2014 at 03:55 PM
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.
Ok I just have changed my code line to transform.Rotate(0, lookAngle, 0); , which I already tried it but I didn't adjust the velocity of rotation, so when I played it the camera just rotate all the time with out control because this value was too high. So thank you robertbu, I am closer to end the control of the character.
Your answer
Follow this Question
Related Questions
Keep camera at certain distance from character when rotating 3 Answers
Get a child object to rotate a parent to the cameras direction -1 Answers
Player rotation = Camera Rotation 0 Answers
RTS Camera movement wrong after rotation 1 Answer
How do i lock the position of the camera above the player relative to the origin point? 0 Answers