New account registrations are disabed. This website is now an archive. Read more here.

Unity    Posted December 11, 2014 by Polraudio

2D Camera Follow Player

Introduction

This is a very very simple camera script that will follow the object named "Player"

Features

Camera will follow the object named "Player"

The Code

License Terms

Attribution 3.0 Unported - You must attribute the work in the manner specified by the author or licensor. Commerical use allowed.

Frequently Asked Questions

Q: Why wont the camera follow my player?
A: Make sure the OBJECT is named Player, not the tag. Also make sure you attached the script to the camera and not the player

Instructions

Step 1:
Attach this script to any camera.

 

Step 2:
Name the object you want the camera to follow "Player" minus the quotes

Author Notes

This script is meant for 2D only. I will not give support if your trying to use it for 3D.

Version History

1.1 – Added ability to zoom in and out via mouse wheel.

Comments (4)

  • Another way to do this is to just drag the main camera object onto the player object in the hierarchy. Any object that is a "child" of another object will move when it's parent does, but can still move independently.

  • Nice little script for a 2d game, i'm contemplating if I should upload my advanced camera script here. (its big and comes in multiple parts (for triggers to control extra movement and stuff). but for 4 lines your script gets the job done for a 2d game.

  • [quote]Another way to do this is to just drag the main camera object onto the player object in the hierarchy. Any object that is a "child" of another object will move when it's parent does, but can still move independently.[/quote] Its a way but the problem with that is when you want to rotate your object for whatever reason the camera will also rotate and it gets very annoying. Especially when you want your character to wobble for moving.

Leave a Reply

Polraudio

  • Posted about 10 years ago

  • Engine
    Unity
  • Category
    Gameplay Scripts
  • License
    Attribution 3.0 Unported
  • Version
    1.1

Stats

2,732 views

4 comments

Tags

n-a