# 2D Smooth Follow with zoom Like Ski Safari Tiny Wings

Discussion in 'Scripting' started by krithik_b007, Jun 13, 2013.

1. ### krithik_b007

Joined:
Jun 12, 2013
Posts:
8
Hello

I am trying achieve smooth follow of the character in Y axis with zoom when the character jumps high similar like Ski Safari .
I am using smooth follow script.

Code (csharp):
1. transform.position = target.position;
2. transform.position -= currentRotation * Vector3.forward * distance;
3. transform.position.x = target.position.x+384;
I Know we need to change the camera orthographic size but it should be very smooth proportionate to the jump.

Regards
Krithik

2. ### lylat

Joined:
Sep 12, 2012
Posts:
28
you could use MoveTowards to smooth the movements for all of them, including the change in camera size.

For the height change you could make it so that:

distance from floor = playerheight - floorheight (determines the distance to the floor)
change in camera size = distance from floor / (the value that will determine how much zoom happens.

camerasize = initialcamerasize + change in camera size

that will need to be coded properly but that is the logic I would use.

3. ### krithik_b007

Joined:
Jun 12, 2013
Posts:
8
Thanks , i will try it out and let you know the result

4. ### lylat

Joined:
Sep 12, 2012
Posts:
28
No worries good luck

5. ### krithik_b007

Joined:
Jun 12, 2013
Posts:
8
Hello Currently i am moving the player in the dynamic terrain with force like

Code (csharp):
But still i am not able to make out like how can we move the camera in Y Axis , just like in Ski Safari .i.e (Player can move in between 250 to 650 in Y axis ) , if he goes above 650 than again camera should follow , same goes when player goes below 250 .

Problem is since i am moving the player (Player pos can go to -10000 in y since he is going down in terrain) and camera s position depends on the player i am not able to calculate these boundary values .

Thank you .

6. ### ar0nax

Joined:
May 26, 2011
Posts:
485
wouldn't it be easier to just parent the camera to the Player and in Update calculate a simple Vector3 offset which you apply to the camera's initial localPosition?

7. ### krithik_b007

Joined:
Jun 12, 2013
Posts:
8
Ah whether we need to add Player inside camera or Camera inside player . If we add Camera inside player , than we need to take care of rotation of camera etc since when player rotates than camera will also rotate (since camera is child) !

I am trying to achieve something like this

8. ### krithik_b007

Joined:
Jun 12, 2013
Posts:
8
Hello

I am new to unity so i want some clarifications.

Current game which i am doing is similar to ski safari , after lot of different approaches i managed to smooth follow with zoom .
But i few queries regarding zoom . The game has 4 layers of parallax movement and i want to zoom only first 2 layers when the player jumps , whether we need to use 2 cameras ? Can we avoid it ? Also when the camera zooms (change in orthographic camera size) the player goes towards center can we avoid this ? i want to keep the player in same x axis whenever i change the orthographic size of the camera .

Thanks

unityunity