Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Writing an offset third-person mouselook camera

Discussion in 'Scripting' started by Nanako, Nov 15, 2014.

  1. Nanako

    Nanako

    Joined:
    Sep 24, 2014
    Posts:
    1,047
    ok i thought this would be easier than it turned out to be, i need a little help.

    What i'm attempting to do is create a camera system like many modern TPS games, but specifically Red Faction Guerilla. here's a quick video:


    The most important thing to note here is that the camera is offset to one side of the player, so that the player appears a little to the left of the screen centre. And, quite significantly, the player is ALWAYS to the left. The player's position in screen space is constant.

    Using mouselook, the camera moves around to show scenery around the player, but always moves in such a way that the player's on-screen position is the same.

    i tried visualising this, and the way i see it, the camera is basically orbiting around the player while ponting at a specific point on a circle, centred on the player. And moving the mouse moves that target point around. I'm not sure how to implement the math for this though, particularly the part about keeping the player's non-centred screenspace position constant

    Although in these videos the player is always looking towards the crosshair, that's actually not even slightly relevant. The player's rotation has nothing to do with this and is a process calculated afterwards. Quite notably, the player character will go into "relaxed" mode after a few seconds of not shooting/being shot, and will stop tracking the crosshair, allowing the camera orbit to show other sides of the player beside his back. That's a feature i'd like to implement too. The camera still functions identically, so any math dependant on anything about the player's facing isn't going to work

    Can someone give me a couple pointers or example of how to do these calculations?
     
    Last edited: Nov 15, 2014
  2. hpjohn

    hpjohn

    Joined:
    Aug 14, 2012
    Posts:
    2,190
    There's really not much too it
    One object (camera pivot) with script controlling it to match the position of the player
    Camera as a child, pointing wherever you want
    Camera control script rotates the pivot for left and right, and tilts the camera up and down

    No maths required on this occasion
     
  3. Nanako

    Nanako

    Joined:
    Sep 24, 2014
    Posts:
    1,047
    I've considered the child object approach, but i've decided it's not suitable for my purposes.

    In any case, i've progressed a bit. What i've got now, is a way to calculate the camera's position when the vector to the focal point is "forward" <0,0,1>

    Can anyone tell me how to rotate the system towards any arbitrary focal point? how do i rotate a vector basically?
     
  4. forbidden

    forbidden

    Joined:
    Mar 6, 2013
    Posts:
    36
    Google 3d buzz the 3rd person camera tutorial and then try again.

    It's a little hard to get working but you can then get the basics.

    Once you get that down then you could adjust the camera look at to right a little.

    I bought a asset on here for 20 even after I took the tutorial but it helped point me in the right direction and helped me a lot.
     
  5. hpjohn

    hpjohn

    Joined:
    Aug 14, 2012
    Posts:
    2,190
  6. Nanako

    Nanako

    Joined:
    Sep 24, 2014
    Posts:
    1,047
    ahh that sounds pretty useful, wish i'd seen this post earlier.

    I have an approximate design drawn up now, was going to attempt to code it tomorrrow. :

    does it sound like it'll work?

    My objective is to have both a focal point, a subject (the player) and a subject offset in screenspace from the centre, as well as a distance parameter (the length along the camera's Z axis where the camera plane intersects the centre of the player) and piece it together as above with these four inputs