Hi guys,

I’ve decided to try my hand at using Unity, and I’ve already hit a bit of a snag. I found someone’s sample settings for a third person camera, and they work pretty well, but have one major problem: no matter what I do, I cannot figure out how to get the camera to focus any higher than the model’s crotch, which is causing his head to get cropped out of the frame. I’m using the included mouse orbit, smooth follow, and smooth look at scripts on the camera, with these settings:

I’ve tried adjusting the height, but that doesn’t seem to actually do anything. Any help with this would be greatly appreciated - I’d like to have my camera over the shoulder, not next to the hip.

My second question is related to the crosshair. I’d to have a crosshair similar to Metroid Prime 3 or the Attack on Titan fan game. In other words, I’d like there to be a box in the center of the screen in which the crosshair can move freely, and only start dragging the camera when it reaches the outside of that box. I’ve never worked with C# or Javascript in my life, so a solution that doesn’t require a whole lot of advanced coding would be ideal.

Thanks.

You’re going to need to get used to working with either one or both of those. Unity is extremely geared towards the programmers.

I’m currently taking intro computer science, and will be learning both of those in it. But at this particular point in time, I have no hands on experience with any programming language except Python. Right now, I just need to get this working, so if you could give me a setting or a line of code and tell me where to put it to at least fix the camera problem, I’d be grateful.

You’ll want to provide us with the camera’s code that you already have.

I’m going to tell you right now that the majority of what you learn about JavaScript will not be applicable in Unity. JavaScript in Unity is a very odd dialect, and so different from actual JavaScript that it’s usually just referred to as UnityScript.

C#, however, that will be good experience.

I’m using three scripts that came with the starter assets.

Smooth Look At:

```
var target : Transform;
var damping = 6.0;
var smooth = true;
@script AddComponentMenu("Camera-Control/Smooth Look At")
function LateUpdate () {
if (target) {
if (smooth)
{
// Look at and dampen the rotation
var rotation = Quaternion.LookRotation(target.position - transform.position);
transform.rotation = Quaternion.Slerp(transform.rotation, rotation, Time.deltaTime * damping);
}
else
{
// Just lookat
transform.LookAt(target);
}
}
}
function Start () {
// Make the rigid body not change rotation
if (rigidbody)
rigidbody.freezeRotation = true;
}
```

Smooth Follow:

```
/*
This camera smoothes out rotation around the y-axis and height.
Horizontal Distance to the target is always fixed.
There are many different ways to smooth the rotation but doing it this way gives you a lot of control over how the camera behaves.
For every of those smoothed values we calculate the wanted value and the current value.
Then we smooth it using the Lerp function.
Then we apply the smoothed values to the transform's position.
*/
// The target we are following
var target : Transform;
// The distance in the x-z plane to the target
var distance = 10.0;
// the height we want the camera to be above the target
var height = 10.0;
// How much we
var heightDamping = 2.0;
var rotationDamping = 3.0;
// Place the script in the Camera-Control group in the component menu
@script AddComponentMenu("Camera-Control/Smooth Follow")
function LateUpdate () {
// Early out if we don't have a target
if (!target)
return;
// Calculate the current rotation angles
var wantedRotationAngle = target.eulerAngles.y;
var wantedHeight = target.position.y + height;
var currentRotationAngle = transform.eulerAngles.y;
var currentHeight = transform.position.y;
// Damp the rotation around the y-axis
currentRotationAngle = Mathf.LerpAngle (currentRotationAngle, wantedRotationAngle, rotationDamping * Time.deltaTime);
// Damp the height
currentHeight = Mathf.Lerp (currentHeight, wantedHeight, heightDamping * Time.deltaTime);
// Convert the angle into a rotation
var currentRotation = Quaternion.Euler (0, currentRotationAngle, 0);
// Set the position of the camera on the x-z plane to:
// distance meters behind the target
transform.position = target.position;
transform.position -= currentRotation * Vector3.forward * distance;
// Set the height of the camera
transform.position.y = currentHeight;
// Always look at the target
transform.LookAt (target);
}
```

Mouse Orbit:

```
var target : Transform;
var distance = 10.0;
var xSpeed = 250.0;
var ySpeed = 120.0;
var yMinLimit = -20;
var yMaxLimit = 80;
private var x = 0.0;
private var y = 0.0;
@script AddComponentMenu("Camera-Control/Mouse Orbit")
function Start () {
var angles = transform.eulerAngles;
x = angles.y;
y = angles.x;
// Make the rigid body not change rotation
if (rigidbody)
rigidbody.freezeRotation = true;
}
function LateUpdate () {
if (target) {
x += Input.GetAxis("Mouse X") * xSpeed * 0.02;
y -= Input.GetAxis("Mouse Y") * ySpeed * 0.02;
y = ClampAngle(y, yMinLimit, yMaxLimit);
var rotation = Quaternion.Euler(y, x, 0);
var position = rotation * Vector3(0.0, 0.0, -distance) + target.position;
transform.rotation = rotation;
transform.position = position;
}
}
static function ClampAngle (angle : float, min : float, max : float) {
if (angle < -360)
angle += 360;
if (angle > 360)
angle -= 360;
return Mathf.Clamp (angle, min, max);
}
```

I’ve tried messing around with the Height variable in Smooth Look At, but it’s not doing anything. I think I might need to adjust the point on the model itself that the camera is looking at, but I can’t quite figure out from the code how I’d go about doing that either.