Camera Folow Problem

Hi guys, finally im starting a personal project out of the work :slight_smile:
Im 3D designer working in video game industry (3d modeling and animation) and im programing a bit.

All is going great very easy, unity is great! i love it.
My project is a scrolling game like the classic Final fight, The Simpsons, Captan Commando, TMNT, etc.

The characters move in the axis X and Z and can jump (Y) but the camera only use axis X ( scroll ).

I tried the SmoothFollow script but the camera move behind my character and is not working like i want.
I tried put the camera inside my character but obviously when my character walk in axis Z the camera too.

So i found this script in Answer Unity Site.

var dampTime : float = 0.3; //offset from the viewport center to fix damping
private var velocity = Vector3.zero;
var target : Transform;

function Update() {
    if(target) {
        var point : Vector3 = camera.WorldToViewportPoint(target.position);
        var delta : Vector3 = target.position - camera.ViewportToWorldPoint(Vector3(0.5, 0.5, point.z));
        var destination : Vector3 = transform.position + delta;
        transform.position = Vector3.SmoothDamp(transform.position, destination, velocity, dampTime);
    }
}

Is following well in the axis X and Z but the camera position is wrong in the axis Y and when my character jump the camera follow him and i don’t want it.

here a link with a test build

http://badmouse.a.lisonal.com/unity3d/

The camera move down automatically and i don’ understand the reason.

checking the position Y of my camera and character i found that the Y position of my Character is 2.8 and the Y position of my Camera is 5.3.

so the camera isn’t follow well my character. the camera move down to 2.8 (character Y position)

how i can fix it?

Here a pic how it looks in Unity

And Here how it look after compile.

Thanks for the help :slight_smile:

Well, you’re telling the camera to follow transform.position.

Instead you need to tell it to follow transform.position + Vector3( 0, 2.8, 0 ).

I think that goes in this line:

var delta : Vector3 = target.position [b]+ Vector3(0,2.8,0)[/b] - camera.ViewportToWorldPoint(Vector3(0.5, 0.5, point.z));

Obviously replacing 2.8 with whatever makes sense for your character. :slight_smile:

Thanks Vicenti, it’s work perfect :slight_smile:

1 more thing, i want to control how much the camera move up when my character jump. not block the axis Y in the camera. just control it.

In the actually build the camera move too much up. is possible control it easily ?

thanks so much for the fast reply :slight_smile:

BTW, i updated the build with you code update.

http://badmouse.a.lisonal.com/unity3d/

And here a pic of how it’s look.

Edit : Is possible control the limit of movement of the camera with the Level Attributes ?
Also I want to limit the borders os the stage.