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 TurboHermit · May 26, 2012 at 09:34 PM · cameraboundsdraggingperspective

Camera Bounds

Hi, I've got a Camera script that makes the camera move by dragging your mouse along the ground's surface. This works fine all in all, but I've ran into some difficulties. It's a topdown Perspective Camera and I wouldn't know how to set boundaries.

I don't want the camera to be able to exit a certain range. I've tried multiple approaches, but I can't get it to work.

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
2
Best Answer

Answer by whydoidoit · May 26, 2012 at 09:43 PM

You need to clamp the position of the camera in your update routine.

Define some variables:

  var minCamera : Vector3;
 var maxCamera: Vector3;

In Update() do:

 transform.position = Vector3(
     Mathf.Clamp(transform.position.x, minCamera.x, maxCamera.x), 

     Mathf.Clamp(transform.position.y, minCamera.y, maxCamera.y), 

     Mathf.Clamp(transform.position.z, minCamera.z, maxCamera.z));

Set your min and max variables and away you go

If you don't need to worry about one of the coordinates, (maybe Y for example) just remove the Mathf.Clamp() and use transform.position.y (or whatever)

Comment
Add comment · 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 TurboHermit · May 27, 2012 at 05:21 PM 0
Share

Works like a charm! Thank you!

avatar image
1

Answer by You! · May 26, 2012 at 09:58 PM

It seems like you need...a conditional statement!!!...and...an empty game object!!!

Back to seriousness. Create the empty game object wherever the center of the game area will be. This object will define where the camera can go. Also, you will need some coding (here it is in Javascript):

 var center : gameObject //the empty game object referred above
 var distance : Vector3 = Vector3.Distance(center,gameObject) 
 
 /*gameObject refers to
 self.  If this script is not attached to the camera, set up another variable (like
 center) for the camera.*/
 
 var edgefactor : int //where is the edge of the game world?
 
 // [skip to wherever the function for the camera begins]
 
 if (distance < edgefactor)
 {
 
 // [insert the stuff that sets up movement here]
 
 }
 else
 {
 
 // Do nothing!
 
 }
 
 // [insert the stuff that actually moves the camera]
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

6 People are following this question.

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

Related Questions

Orthographic position to Perspective position 0 Answers

How to do perspective camera zoom? 1 Answer

How to implement a 3/4 perspective camera 1 Answer

Transition a camera from ortographic to perspective mode (Trombone effect) 2 Answers

Keep Cursor In Bounds of Camera 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