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
1
Question by CodeElemental · Feb 06, 2014 at 02:32 PM · cameraviewportisometric

Isometric Camera : Get the displayed terrain portion.

alt text

How can i get the portion of the terrain i'm viewing with my isometric camera (as in the picture)? The only thing I can think of is getting the raycast of the camera to get the center of the rect (intersect with terrain) and then somehow extrapolate the four corners.

I'm using this to highlight a viewport on my minimap.

isometric-view.png (11.6 kB)
Comment
Add comment · Show 3
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 Mortoc · Feb 06, 2014 at 02:33 PM 0
Share

Is your terrain always a flat plane?

avatar image CodeElemental · Feb 06, 2014 at 02:37 PM 0
Share

Yes. No height variations.

avatar image Mortoc · Feb 07, 2014 at 09:32 PM 0
Share

This is a pretty common problem and I think between your diagram and my code sample it came out fairly well. If you think so, would you $$anonymous$$d marking my answer as accepted so we can have this show up for future users asking similar questions?

1 Reply

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

Answer by Mortoc · Feb 06, 2014 at 03:21 PM

 // assuming the ground is on it's own layer called 'ground-plane'
 int mask = 1 << LayerMask.NameToLayer("ground-plane");
 
 // get the 2 camera-corner rays
 Ray topRightRay = Camera.main.ViewportPointToRay(Vector3.zero);
 Ray bottomLeftRay = Camera.main.ViewportPointToRay(Vector3.one);
 
 // find the corners of the terrain-rect 
 RaycastHit topRightRH;
 RaycastHit bottomLeftRH;
 Rect result;
 if( Physics.Raycast(topRightRay, out topRightRH, Mathf.Infinity, mask) && Physics.Raycast(bottomLeftRay , out bottomLeftRH, Mathf.Infinity, mask) )
 {
     result = Rect.MinMaxRect(topRightRH.point.x, topRightRH.point.y, bottomLeftRH.point.x, bottomLeftRH.point.y);
 }
 else
 {
     throw new InvalidOperationException("Cannot get the terrain rect when the camera isn't completely over the terrain");
 }
 
 return result;
 
Comment
Add comment · Show 3 · 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 CodeElemental · Feb 06, 2014 at 08:10 PM 0
Share

Was thinking of something in this direction myself, i'll check if it works when i have the time. Thanks for the reply.

avatar image CodeElemental · Feb 07, 2014 at 09:18 AM 0
Share

From the ViewportPointToRay documentation the coordinates retrieved by Raycasting were mixed up. It should be topRight, and bottomLeft accordingly. The logic returns the desired result.

avatar image Mortoc · Feb 07, 2014 at 04:00 PM 0
Share

Yah, I was thinking I might have swapped that a bit - I was writing that from memory. Fixed now.

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

20 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

Related Questions

Center Object in Viewport 1 Answer

What is the best way to use the bounds of the camera in-world effectively? 1 Answer

Changing the Camera viewport rect results in resizing the objects rendered by the specific camera ? 1 Answer

How to make camera position relative to a specific target. 1 Answer

possible to set rotation of camera viewport? 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