# Camera Offset Relative to Characters Transforms

I have a camera following a character around a sphere, like Super Mario Galaxies, with and offset of 1. When on top of the sphere the offset is correct, and the camera is above the character. But when on the bottom of the sphere the camera is now under the character looking up instead of above the character looking down. It looks like it is targeting the character, but and keeping a positive 1 offset relative to the world.

can anyone help?

if you post your code relating to how it is following your character model it may give us a better idea of what you are trying to do, and what may be causing the problem.

Here is what I’m using for the camera

var target : Transform;
public var distance = 0;
public var targetHeight = 0;
private var x = 0.0;
private var y = 0.0;
private var z = 0.0;

function Start () {
var angles = transform.eulerAngles;
x = angles.x;
y = angles.y;
z = angles.z;
}

function LateUpdate () {
if(!target)
return;

y = target.eulerAngles.y;
x = target.eulerAngles.x;
z = target.eulerAngles.z;

// ROTATE CAMERA:
var rotation:Quaternion = Quaternion.Euler(x, y, z);
transform.rotation = rotation;

// POSITION CAMERA:
var position = target.position - (rotation * Vector3.forward * distance + Vector3(0,-targetHeight,0));
transform.position = position;

}

are you setting variables in the inspector? rather then in code?

One some yeah, on the ones marked private i set in code, but have been playing with the values. It be easier if i make the all public for now.

i was setting them mainly because it made iteration fast, but either way is fine.

the reason I am wondering is because if any of those values not shown affect the distance, then they may have some merit in this current situation.

the lines marked private give it a offset, which is what i want. But when the character is on the bottom of the sphere the offset is relative to the world and not localized to the character,

Ideally would like the camera to be locked to the characters transforms with an adjustable offset.

lol, turns out i was over complicating it. Removing the script and making the camera a child of the character did the trick.

thanks for the help,