Search Unity

Over-shoulder Camera System

Discussion in 'Editor & General Support' started by Chabby, Mar 31, 2011.

  1. Chabby

    Chabby

    Joined:
    Mar 31, 2011
    Posts:
    4
    Greetings,

    I'm having some sort of an issue here. We're learning Unity's bases at school, which implies creating a playable level with a third-person system.

    The thing is, I'd like to have a over-shoulder camera system, a bit like Gears of War/Resident Evil 4-5, etc. Just having the camera positioned correctly (like the image bellow) which also rotates with the characters (so the camera always follows the character in other words).
    Ref: http://img.youtube.com/vi/woFOm2Fg_2k/0.jpg

    I don't need any 'press button to aim' or 'shake the camera when the characters run', only the position. I browsed the Support forum and searched through threads but couldn't manage to find an answer.

    Thank you! :)
     
  2. 2dfxman1

    2dfxman1

    Joined:
    Oct 6, 2010
    Posts:
    1,065
    Do you have the camera script itself? If not, take one from wiki. Then all you need to do is make an empty gameobject that will serve as a target and place it where you want it, then parent it to your character. Then using a camera script, just pick that empty object as target and there you go.
    That's the most basic and dirty way
     
  3. PrimeDerektive

    PrimeDerektive

    Joined:
    Dec 13, 2009
    Posts:
    3,090
    To expound upon what 2dfxman said, I personally use the Orbit Camera script from the 3rd person platformer tutorial from the resources section, just download the project and grab it. (It's a lot like the stock mouse orbit camera, except it avoids clipping with level geometry which is nice).

    Then make your character use the standard FPSInputController/CharacterMotor combo (unless you wrote your own input sheme), and as 2dfx said, create an empty gameobject and parent it to your player, position it off to the right a few feet at shoulder level, and make that the camera's target (not the player).

    The only problem now is you need the player to always face the same direction as the camera like it does in other TPS games, so you'd put a simple script on your player object that basically just says:

    Code (csharp):
    1.  
    2. function LateUpdate(){
    3.     transform.rotation.y = Camera.main.transform.rotation.y;
    4. }
    5.  
    There might be a little bit of jitteryness with that last bit, if you change the OrbitCamera to use Update() instead of LateUpdate(), it will smooth it out.
     
    Last edited: Mar 31, 2011
  4. Chabby

    Chabby

    Joined:
    Mar 31, 2011
    Posts:
    4
    Thanks for the answer, I am using the standard Characters Controller included with Unity, which means I'm using the ThirdPersonCamera script.

    I tried using a custom camera with a target, but I always get the same conclusion: It get buggy/glitchy and I can't go further.
     
  5. Chabby

    Chabby

    Joined:
    Mar 31, 2011
    Posts:
    4
    Okay, so thanks to your advices, I managed to get something really interesting.

    But now I ask, is it possible to remove the 'aiming with mouse' function in order to keep the camera behing the character whatever we do?
    Or perhaps my newbie skills didn't help lol.

    So:

    I created a target and placed it.
    Created a camera.
    Assigned the OrbitCamera script to the Camera.
    Assigned the script given by legend411 to my character.
    Added the FPSControllerInput with Character Motor to my character.
    Kept the ThirdCharacterController on my character in order to keep its animation.

    Now, as I said, the camera is placed correctly, but the character doesn't rotate with the camera angles, it's independant, which is a problem because the character walks sideway, unable to rotate, while the camera (moved with the mouse) rotate around him.

    Thanks :)
     
    Last edited: Mar 31, 2011
  6. PrimeDerektive

    PrimeDerektive

    Joined:
    Dec 13, 2009
    Posts:
    3,090
    That's pretty much what i was trying to explain with the code snippet i posted: instead of keeping the camera behind the character, make the character always face the direction the camera is pointing (as a result, the camera will always be behind him).