2D camera center and follow

Hi, I have a 2D game that shows several NPCs on the screen at a time. The NPCs move about on their own. I would like to have it so when the user clicks on one of the NPCs, it centers on him and follows him around.
Then, if the user clicks elseware (not on an NPC or GUI item) the camera re-centers to a default location.

I’m sure I’m missing something simple. So far I’m using only the default main camera settings

Thanks!!

Rai :slight_smile:

Hi Ray, you should be able to easily adapt the script that I gave this guy to do what you need :

You just need to make it work in the dimensional axis that suits your 2D viewpoint, and set your clicked upon object as the current target for it(it currently finds and uses the “Main Camera” as its target), then set back to your default target after.

You may also want to make it lerp to its new position so you get a nice smooth transition when it moves between target objects.