paralax scrolling in orthographic scene

heres my script… it works kinda ok but after my players.transform.position.x changes alot it starts acting strange… I know theres something seriously wrong with the script i just dont have the brainpower to fix it myself

 var player : Transform;
var depthspeed =-0.1;
var pos=0;
var v2dist=0;
var range = 60;
function Awake(){

pos =transform.position.x ;

transform.position.x =(player.transform.position.x*depthspeed)+pos;
}
function Update () {




var v2dist= Vector2.Distance(player.transform.position,transform.position);




if(v2dist < range){

transform.position.x =(player.transform.position.x*depthspeed)+pos;
}

    
    
}

:edit SOLVED - smart man u are @nsejosh! thanks a million

I don’t think you want

var v2dist= Vector2.Distance(player.transform.position,transform.position);

because that measures the distance in x and y.

shouldn’t the range be based on only x? if you’re using y, then when the play moves in y, you could go out of range, regardless of your x.

also, I think you want to judge the range based on the original position of the object, not the parallaxed version. try this:

var v2dist = Mathf.Abs( player.transform.position.x - pos.x )

and adjust your range accordingly.

formated the code properly! sorry bout that!