Over-the-shoulder third person camera giving me grief!

Hello! I'm trying to get an over-the-shoulder sort of look, using the standard MouseOrbit script and my own script to have the player turn to look towards where the camera is pointed.

My script is:

var cam : Camera;

function Update () {
    var d3Point = cam.ScreenToWorldPoint(Vector3(cam.pixelWidth/2, cam.pixelHeight/2,50));
    transform.LookAt(d3Point);
}

What is happening instead is that the camera jumps right behind the object, instead of off to the side. The player (just a cube with a cylinder attached) still looks where I point, but the view is all off. Instead of over-the-shoulder, it's right behind the cube. What I want:

o= camera | = body

o----

|----

What I get:

o-|----

I have: Player

       Body

         Gun

       Main Camera  </p>

with the turn script attached to Body (the one above) and the standard MouseOrbit on the Main Camera, with body fed in. (oh and main camera attached to cam on the turn script)

(THe full, small project: http://www.mediafire.com/?iwtwynmmm2t)

Why dont you try this:

I assume your Player hierarchy is like this:

Player

Body

Gun

Create an empty gameObject and call it 'Shoulder'. Make shoulder a child of Player, and position at the offset you want the camera to be looking:

Player

Body

Gun

Shoulder

Use a script to point the camera at the shoulder object/rotate around it.

This way, if you use mouse looking to rotate the view, the player will still be in view but you get the over the shoulder look. Also, in this way, if the player moves forward or back, strafes, or jumps, the camera will track that movement because the shoulder object is a child of the player.

You might want to look at the 3rd Person Shooter demo which has a 3rd person camera and a character that turns to look where the camera is looking.