Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 Besi2019 · Apr 16, 2018 at 09:06 PM · cameracamera-movementcamera viewport

Camera view level

Ive attached an image, because its hard to explain what I want.

What I want to acheive is: The camera should follow the lightblue color. Right now the camera is following the player, and thats all good, but some places in the game, I want the camera not to follow. How to do that? ?alt text

camera.png (8.1 kB)
Comment
Add comment · Show 4
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 GMAGames · Apr 16, 2018 at 09:28 PM -1
Share

the camera will be facing hole level you can't poisiton it in 2d games like this

avatar image GMAGames · Apr 16, 2018 at 09:29 PM -1
Share

maybe in platform game

avatar image Bunny83 · Apr 16, 2018 at 10:42 PM 0
Share

Sorry i have no idea what you trying to ask here. I can tell you want i see here: I see a 2d level layout with platforms, killplanes and i guess the cyan area should be the area where the player should be able to move? What do you actually want to achieve? Do you want to restrict the camera during gameplay? Do you want to render such an image as sort of overview?


This is not a valid question. Please clarify by editing your question.

avatar image Besi2019 Bunny83 · Apr 17, 2018 at 05:36 AM 0
Share

Ive edited my question. Hope it makes sense now.

2 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by Harinezumi · Apr 17, 2018 at 08:06 AM

If I understand correctly, you would like the camera to follow the player, but restricted to the area marked light blue. If this is correct, then what I would do is to use BoxColliders marked trigger (possibly on their own layer), with scripts on them defining limits, and the camera with a script that looks for the script that defines the limits, and applies it (I once wrote such a system, and it's not difficult, but not trivial either).
Something along these lines:

 // put this on your objects that represent the camera movement limits
 public class BoxLimit : MonoBehaviour {
 
     [SerializeField] private Vector3 extents; // the size of the limits
     public Vector3 GetExtents() { return extents; }
 
     // this helps visualize the limits
     private void OnDrawGizmosSelected() {
         Gizmos.color = Color.cyan;
         Gizmos.DrawWireCube(transform.position, extents);
     }
 
 }

 // put this on your camera
 public class MovementLimiter : MonoBehaviour {
 
     // it's even better if you use a List<BoxLimit> in case there are overlapping areas
     private BoxLimit currentLimit;
 
     private void OnTriggerEnter (Collider other) {
         BoxLimit boxLimit = other.GetComponent<BoxLimit>();
         if (boxLimit != null) {
             currentLimit = boxLimit;
         }
     }
 
     private void OnTriggerExit (Collider other) {
         BoxLimit boxLimit = other.GetComponent<BoxLimit>();
         if (boxLimit != null && currentLimit == boxLimit) {
             currentLimit = null;
         }        
     }

     // using LateUpdate() to limit position after all movement is done
     private void LateUpdate () {
         if (currentLimit != null) {
             // get limit variables
             Vector3 limitPosition = currentLimit.transform.position;
             Vector3 limitExtents = currentLimit.GetExtents() * 0.5f; // halved, because we consider distance from center, not whole scale
 
             // calculate limits
             Vector3 lowLimit = limitPosition - limitExtents;
             Vector3 highLimit = limitPosition + limitExtents;
 
             // limit position
             Vector3 position = transform.position;
             position.x = Mathf.Clamp(position.x, lowLimit.x, highLimit.x);
             position.y = Mathf.Clamp(position.y, lowLimit.y, highLimit.y);
             position.z = Mathf.Clamp(position.z, lowLimit.z, highLimit.z);
 
             // apply position
             transform.position = position;
         }
     }
 
 }
Comment
Add comment · Show 4 · 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 Besi2019 · Apr 17, 2018 at 08:43 AM 0
Share

Okay thanks. Yes thats correct, im looking something like that. I will try your suggestion

avatar image Besi2019 · Apr 17, 2018 at 08:50 AM 0
Share

Can I make multiply cameras, and give each camera there own position and areas?

avatar image GMAGames Besi2019 · Apr 17, 2018 at 09:01 AM -1
Share

i think that will you

avatar image Harinezumi Besi2019 · Apr 17, 2018 at 09:03 AM 0
Share

You can have multiple cameras (in fact, this is about positions, there is nothing about cameras!), but you would need some way to deter$$anonymous$$e which area belongs to which camera.
One simple way is to add a readable int areaId to BoxLimit and $$anonymous$$ovementLimiter, and in $$anonymous$$ovementLimiter.OnTriggerEnter() only assign it as currentLimit if the area IDs match.

 // add these to both classes, although $$anonymous$$ovementLimiter does not necessarily need the getter
 [SerializeField] private int areaId;
 public int GetAreaId () { return areaId; }
 
 // in $$anonymous$$ovementLimiter.OnTriggerEnter()
 BoxLimit boxLimit = ...;
 if (boxLimit != null && boxLimit.GetAreaId() == areaId) {
     ...
 }
avatar image
-2

Answer by GMAGames · Apr 16, 2018 at 09:27 PM

you can't in 2d mode

Comment
Add comment · Show 2 · 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 Bunny83 · Apr 16, 2018 at 10:44 PM 1
Share

Are you serious? There's almost nothing that can't be achieved, though i highly doubt we actually know what he's asking here.

avatar image GMAGames · Apr 17, 2018 at 09:00 AM 0
Share

Sorry i was thinking that he want to position the camera in 2d mode like the picture says

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

132 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 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 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 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 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 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

Change cameras visible area in camera viewport 0 Answers

I can not find Cinemachine in package manager. There is no option of 'All Assets in package manager.' 1 Answer

How to open the resources from a downloaded game to add another viewpoint? 0 Answers

How can I mimic a Camera from a game to my project? 1 Answer

Finding the angle at which the edges of a camera shoot out 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