Camera follow an object on just z-axis.

Hello, i am working on a bike came and i want to move my camera which just follow my bike. i am using smooth follow script but when i change my lane, my camera also change its position to x axis. which i do not want. i have tried to make changes in SmoothFollow script but could get to the right direction.

can anybody give me some hint to to achieve that as i am new in unity.

thanks

Instead of following your bike, your camera needs to follow some stub. The stub doesn’t change lanes. So you need to let the stub update the positions of the bike in only 2 directions and let the third out. This way, you don’t need to change the smoothFollow script.

var target : Transform;
var distance : float = 10.0;

function Update(){
transform.position.z = target.position.z - distance;

}

Hey Sajjo I have the same problem and I did not understood what Marnix is trying to say May i get the help for the same ?

I am trying to make game like Air Strike 3D where camera moves along in z axis but if plane goes in left then screen or say camera also scrolls along x axis for about 5 meter…same shd happen for right

Please help me regarding the camera view…

Thanks in advance

Thanks taddmencer for your instant reply but this is not what I want just check out Air Strike 3D game where camera is not working as smooth flow to player but something else I am not able to figure that out.

I will give you link of youtube please check this and if u will be able to help me i will be very helpful

this is the link

check the video after 4.42 minutes to avoid the information screen and all…

See in that screen scrolls little bit left …right and i dont think its smooth follow if it is then please provide me the solution…if possible i will be very thankful…

Use this on you main camera, i am very new to c# but I think I made a stream-lined, efficient script to follow any player on ONLY the z-axis.

using UnityEngine;
using System.Collections;

public class CameraBehaviors : MonoBehaviour {

public Transform player;

private float playerZ;

private Vector3 follow;

// Use this for initialization
void Start () {

}

// Update is called once per frame
void Update () {
	playerZ = player[0].position.z - 2;
	follow = new Vector3(0f,8.23f,playerZ);
	transform.position = follow;
}

}

The part where I describe the Y axis for “follow” it just how high you want the camera, that can be changed to your liking. also the -2 in “playerZ” it just so the camera is slightly behind the player.

Hope this script helped!