- Home /
Camera follow 2D sprite when it goes off screen
I just want help making a simple script that will make the camera follow my sprite when its position is farther then the screen size just like any 2D tile engine game has. I don't want a script written for me I just want an explanation of how I could do it. Of course I just want it to follow on the x and y axis.
I don't understand what you mean. A sprite is displayed on the camera, so how can the camera follow it ? You want a "snake-effect", your sprite leaving on the right and reappearing on the left ?
I am using orthello2D. I figured it out anyway. I was doing the Vector3s separate like transform.position.x = the target.position.x ins$$anonymous$$d of doing it this way
transform.position = new Vector3(target.transform.position.x, target.transform.position.y, 0);
It works perfect.
Answer by funfair · Feb 10, 2012 at 07:16 AM
if you would like the camera stick on the target, why don't you just put the camera as a child of the target ?
That didn't work it was the first thing I tried. This worked transform.position = new Vector3(target.transform.position.x, target.transform.position.y, 0);