Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • 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
0
Question by SuperBiasedMan · May 21, 2013 at 05:38 PM · 2d platformerpan2d camera

How to stop a camera panning at level boundaries while zooming?

Apologies if this has been asked before, but it's slightly different to what I kept finding when I tried searching.

I have a camera that follows a character in a 2D platformer style game. I already know a simple way to stop it moving past the level boundaries normally is to use MathClamp on its position.

But there's one point of the level where the orthographic camera zooms out as the character climbs steps, making it harder to pinpoint exactly what position the value should be clamped at.

Is there a simple way to find the X and Y values of the screen boundaries or should I just find it by trial and error, editing values?

Comment
Add comment
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

2 Replies

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by robertbu · May 21, 2013 at 05:52 PM

Convert viewport coordinates into wold coordinates. Viewport coordinates start at (0,0) in the lower left of the screen and reach (1,1) in the upper right. You need to know the distance between the camera and the point you want to convert which should be easy with a 2D game. The Z parameter of ViewportToWorldPos() gets the distance from the camera, and this code uses 10. Replace with your actual distance:

 var v3WorldPosLL = Camera.main.ViewportToWorldPoint(Vector3(0,0,10));
 var v3WorldPosUR = Camera.main.ViewportToWorldPoint(Vector3(1,1,10));

With these two positions, you can calculate the other two points as well as get the height/width if needed.

Comment
Add comment · 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
0

Answer by deek0146 · May 21, 2013 at 06:06 PM

Say your level size is the Vector2 Ldim.

The camera at it's current level of zoom is able to see rectangular area of the level Vdim. You can calculate Vdim using the distance between the camera and the level, and the view frustum of the camera. There are utilities in the Camera component to help with this, if you need me to explain exactly how to do this, comment and I will do so.

Your camera needs to be bound to a plane whose dimensions is equal to Ldim - (Vdim*0.5f)

Comment
Add comment · 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

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

14 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

Related Questions

Apple like camera Panning(Finding mouse speed and apply it to camera) 0 Answers

Pan Orthographic camera in 3D 4 Answers

2dToolkit and Physics2D.OverlapCircle 2 Answers

Inconsistent 2D collision detection since 5.2.3 1 Answer

Deactivate Key. 2 Answers


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