Another smooth camera question

Hi! im really new to scripting and coding and just starting to learn so please be kind to me :smiley: i tried to look other similar questions here but it didnt help, so here is my question:

Im trying to make camera move smoothly from left to right (in 2D side scroller) when player turns.
i have camera following an empty gameobject in front of the player model and i have this script in that empty gameobject:

function Update () {
if(Input.GetAxis("Horizontal") > 0)
transform.localPosition = Vector3(4,0,0);
else if(Input.GetAxis("Horizontal") < 0)
transform.position = Vector3(-4,0,0);
}

But the problem is how i get it to move smoothly between those points?

You need to research Vector3.MoveTowards() and Vector3.Lerp() for movement over time. There are lots of posts on UA on the use of both. iTween as mentioned by @DJ-Switi is as option as well as MoveObject script. Here is a quick rewrite of your code using MoveTowards().

#pragma strict

private var pos = Vector3.zero;
private var speed = 1.0;

function Update () {
	if(Input.GetAxis("Horizontal") > 0)
		pos = Vector3(4,0,0);
	else if(Input.GetAxis("Horizontal") < 0)
		pos = Vector3(-4,0,0);
		
	transform.position = Vector3.MoveTowards(transform.position, pos, Time.deltaTime * speed);
}