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 giantrobotbee · Jan 31, 2015 at 07:25 PM · camera2dside-scrolling

Determine if GameObject with no renderer is within Orthographic camera bounds

I have a 2D sidescrolling game that is pseudo randomly generated. It reads in "rooms" which are 10x10 tile segments. I have a GameObject Room which basically manages all the tiles, which are 2D sprites. The Room class has no renderer itself, but it does have a Bounds member that wraps the bounds of all the tiles it contains. Rooms are positioned directly next to each other to appear as once seamless level.

I have the camera scrolling to the right and want to test when a Room leaves the Ortho camera's view so I can dispose of the room and recycle it at the other end of the level.

Trying common methods for this such as GeometryUtility.TestPlanesAABB(planes, rooms[0].RoomBounds) does not yield the right behaviour. It returns true long after the room has apparently left the camera's view. It eventually returns false, but not until it has crossed the mid-point of the NEXT room.

I believe it's likely I'm not understanding something about that test and how it works, or perhaps it isn't intended for an ortho camera.

FWIW, the "Rooms" area always smaller than the width of the camera. With the camera still, and the first room at the far left of the viewport, ~1.5 rooms are within the camera's view.

Does anyone know the proper way to test something like this. Most examples I've seen require the object you're testing to have a renderer of some sort. Thanks in advanced!

Comment
Add comment · Show 2
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 VesuvianPrime · Jan 31, 2015 at 07:55 PM 0
Share

I would expect the TestPlanesAABB approach to work. Perhaps you could draw the bounds of the room to ensure the bounding box is correct?

 public static void DrawBounds(Bounds bounds, Color color, float duration)
 {
     Vector3 $$anonymous$$ = bounds.$$anonymous$$;
     Vector3 max = bounds.max;
 
     // Bottom square
     Debug.DrawLine(new Vector3($$anonymous$$.x, $$anonymous$$.y, $$anonymous$$.z), new Vector3($$anonymous$$.x, $$anonymous$$.y, max.z), color, duration);
     Debug.DrawLine(new Vector3(max.x, $$anonymous$$.y, $$anonymous$$.z), new Vector3(max.x, $$anonymous$$.y, max.z), color, duration);
     Debug.DrawLine(new Vector3($$anonymous$$.x, $$anonymous$$.y, $$anonymous$$.z), new Vector3(max.x, $$anonymous$$.y, $$anonymous$$.z), color, duration);
     Debug.DrawLine(new Vector3($$anonymous$$.x, $$anonymous$$.y, max.z), new Vector3(max.x, $$anonymous$$.y, max.z), color, duration);
 
     // Top square
     Debug.DrawLine(new Vector3($$anonymous$$.x, max.y, $$anonymous$$.z), new Vector3($$anonymous$$.x, max.y, max.z), color, duration);
     Debug.DrawLine(new Vector3(max.x, max.y, $$anonymous$$.z), new Vector3(max.x, max.y, max.z), color, duration);
     Debug.DrawLine(new Vector3($$anonymous$$.x, max.y, $$anonymous$$.z), new Vector3(max.x, max.y, $$anonymous$$.z), color, duration);
     Debug.DrawLine(new Vector3($$anonymous$$.x, max.y, max.z), new Vector3(max.x, max.y, max.z), color, duration);
 
     // Struts
     Debug.DrawLine(new Vector3($$anonymous$$.x, $$anonymous$$.y, $$anonymous$$.z), new Vector3($$anonymous$$.x, max.y, $$anonymous$$.z), color, duration);
     Debug.DrawLine(new Vector3($$anonymous$$.x, $$anonymous$$.y, max.z), new Vector3($$anonymous$$.x, max.y, max.z), color, duration);
     Debug.DrawLine(new Vector3(max.x, $$anonymous$$.y, $$anonymous$$.z), new Vector3(max.x, max.y, $$anonymous$$.z), color, duration);
     Debug.DrawLine(new Vector3(max.x, $$anonymous$$.y, max.z), new Vector3(max.x, max.y, max.z), color, duration);
 }
avatar image giantrobotbee · Jan 31, 2015 at 08:45 PM 0
Share

Ah ha! $$anonymous$$y bounds are not positioned where I think they are. I think I've found the culprit! Thank you.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by TBernard · Jan 31, 2015 at 07:43 PM

Maybe I missed something but can't you use the extents and center of the bounds component and the center, orthographicSize and aspect ratio of the camera to calculate if the left/right edges of the room are still within the camera's viewport?

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Assets/Scripts/PlayerController.cs(32,49): error CS0126: An object of a type convertible to `float' is required for the return statement 1 Answer

2D Camera "Smooth Follow" 9 Answers

2D Camera follow player up but not down 1 Answer

2D Camera Collision 1 Answer

i want the camera stop follwing my player only on y axis when he jumps... 4 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