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 Recluse · May 26, 2011 at 01:05 PM · collidertriggerpositionobjectrandomemptylandscape

What's the best way to check if an area is empty?

I have an object which I need to reposition randomly.

I need to make sure I don't position it inside parts of the landscape, which is also generated randomly.

OnTriggerNull would be nice, but there's no such function.

Any ideas?

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

7 Replies

· Add your reply
  • Sort: 
avatar image
2

Answer by Graham-Dunnett · May 26, 2011 at 01:21 PM

Choose a x and a z position randomly, then fire a ray from high up in y downwards. Place the object where the ray hits the landscape. (Assuming your world has y pointing upwards.)

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 almo · May 26, 2011 at 01:21 PM 0
Share

He beat me to it. $$anonymous$$y first post went to another question, so I had to delete it, then repost it.

avatar image
0

Answer by almo · May 26, 2011 at 01:21 PM

You could pick a random X,Z location, and pick a Y location higher than anything in the landscape, and do a raycast down from there. Then place the object where the raycast hits.

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
avatar image
0

Answer by Recluse · May 26, 2011 at 02:11 PM

Thanks Graham - I had thought of using Raycasting, but I need to check a cubic area, which means casting three rays minimum and which would still not be faultless, due to the angled geometry of the landscape. I want to make sure my Pickup object is not partially located in a wall, tree, rock etc.

Currently I am positioning the object and if it collides with something I reposition it until it doesn't - which is a bit clunky. All this happens out of sight of the player, but I'd like to find a really elegant way of doing it. Neither this nor Raycasting is that tidy (would love OnTriggerNull - wouldn't that be useful?)

Hmmmm....

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 DaveA · May 26, 2011 at 05:00 PM 0
Share

Please use 'comment' not 'answer' to comment on other posts.

avatar image
0

Answer by Recluse · May 26, 2011 at 02:17 PM

The landscape is a cavern / tunnel with lots of obstructions. I just need a foolproof way of finding nice empty spots in it. So far can't think of anything simpler than just randomly positioning the object repeatedly until OnTriggerEnter fails to flag a collision.

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 save · May 26, 2011 at 02:41 PM 0
Share

This might be a weird suggestion but could possibly work. How about an empty spinning and moving gameobject that shoots a ray?

avatar image save · May 26, 2011 at 02:48 PM 0
Share

Or iterate through positions in a grid inside the tunnel area.

avatar image
0

Answer by homeros · May 26, 2011 at 05:25 PM

How about using an invisible mesh smaller than tunnels to specify areas you can spawn the object. You can use random coordinates from collider.bounds or generate random numbers and check if the collider contains them?

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
  • 1
  • 2
  • ›

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

Object detection in front of Character 1 Answer

Detecting another object collision from another object script (2D) 0 Answers

Enable objects to enter the trigger 2 Answers

Simple Colliders Question 1 Answer

Distinguish between two colliding objects 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