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 dumbat · Jun 11, 2014 at 11:39 AM · 2dcollisiontrigger

Find the highest point of a stack of gameobjects

I am writing a 2D game. I have a jumbled pile of gameObjects and I want to work out the highest point of the highest of those objects. I was going to use a kinematic trigger object and move it downwards until it hit something, but moving it by code doesn't cause any OnTriggerEnter2D or OnCollisionEnter2D calls. I'm sure there must be a more sensible way to measure it than by dropping a collider onto the pile - can someone point me in the right direction?

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 HarshadK · Jun 11, 2014 at 12:38 PM

You can store the position transform of all your game objects in an array or list and then find the game object with highest 'y' value for the position (assuming you are using 'y' value to check the highest position) using any basic sort algorithm like bubble sort.

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 dumbat · Jun 11, 2014 at 12:42 PM 0
Share

That would find the highest centre of an object, but I want to find the highest point of the highest object. I guess I could use the object's bounds, but then an object with a lower y might be larger and have a higher high point.

avatar image HarshadK · Jun 11, 2014 at 12:43 PM 1
Share

Then you can add up the values of bounds of all the game objects that are in the stack to get the highest point.

avatar image dumbat · Jun 11, 2014 at 12:46 PM 0
Share

Yes I reckon that's going to be the fastest and simplest solution. Thanks!

avatar image eliweston · Apr 12, 2018 at 01:39 AM 0
Share

This is a 100x harder then you make it sound.

avatar image
0

Answer by FabDynamic · Apr 12, 2018 at 02:20 AM

This is similar to the answer by @HarshadK

Step 1: Figure out how to obtain the HighestPoint for each object Step 2: Use Step 1 to obtain a list of all HighestPoints Step 3: Sort the list

I'm going to presume that you can do Steps 2 and 3 but step 1 is tricky. To do this use the renderer bounds which are in world coordinates (not the mesh bounds). To get these values you will need to use:

     <Insert gameobject here>.GetComponent<Renderer>().bounds.max.y

I hope that helps.

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

23 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

Related Questions

[2020.3][2D Collision] Trigger collider with physics computation 0 Answers

OnTriggerEnter2D problem on created collider2d and rigidbody2d during runtime 0 Answers

Trigerrs Logic problem with collision damage 1 Answer

OnTriggerExit2D not working, but OnTriggerEnter2D does??? 5 Answers

How to use Physics2D.IgnoreCollision2D in Unity 5 to cancel a trigger 0 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