• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
Question by HighCode · Jun 08, 2014 at 02:45 AM · camera2dplatformer

Restricting camera to within areas. 2D Adventure Platformer

I'm working on a 2D Platformer and currently the camera just follows the character wherever, keeping him in the center of the screen. However, if I could restrict the camera to certain areas, i would know exactly what the player sees, rather than part of the camera going beyond the areas the character can reach. An example would be if I had two rooms above eachother, the camera would need to zoom in to stay within the bounds of that area, so as not to show anything in the next area above.

It's hard for me to describe exactly how I see it, so I made a picture.

alt text

I'm not sure if the easiest way would be to give all the surrounding platforms a certain tag that the camera would look for, or if I should mess with colliders...

Sorry if this is a stupid question.

untitled drawing (1).png (17.4 kB)
Comment

People who like this

0 Show 0
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

  • Sort: 
avatar image
Best Answer

Answer by Dizzyman572 · Jun 08, 2014 at 03:17 AM

Here's one trick that could probably work for you. Remove your camera as a parent of your character and then manually program your camera to follow your character's position along the X and Y axis. Your character should still be at the center of the screen. From there you can use if statements to tell your camera "If your position along the X axis is great than or equal to 10, do not stop follow the transform. If your position along the X axis is less than or equal to -10, do not follow the player." Then you just declare a few integer variables stating the maximum and minimum parameters. If you set these variables to be public, you should be able to tweak these variables to meet the needs of the level your making considering that you use different cameras for different scenes. I hope that helps.

Comment

People who like this

0 Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Dizzyman572 · Jun 10, 2014 at 05:33 PM 0
Share

And no, this isn't a stupid question at all.

Unity Answers is in Read-Only mode

Unity Answers content will be migrated to a new Community platform and we are aiming to launch a public beta by June 9. Please note, Unity Answers is now in read-only so we can prepare for the final data migration.

For more information and updates, please read our full announcement thread in the Unity Forum.

Follow this Question

Answers Answers and Comments

22 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

2D Platformer Demo Camera Follow script doesn't follow player 1 Answer

Cinemachine camera weird movement on Windows build 0 Answers

ScreenToWorldPoint not accurate 0 Answers

Lock main camera on x-axis 2 Answers

2.5D Platformer Camera follow character Y axis but not for every jump? 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges