Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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 FusionSausage · Sep 28, 2013 at 05:15 PM · c#terrainbuildzonedivide

Distribute terrain in zones

Hi, I have a terrain made up with mountains and flatland. Now I've come to the part where the player should be able to build in the flat areas but not on the mountain. The solution I thought of was to divide the terrain into zones. The flatland could be "zone 1" or just "flatland zone" and the mountains could be "zone 2" or "mountain zone". Which way would be the easiest to do this?

Thank you!

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

3 Replies

· Add your reply
  • Sort: 
avatar image
5

Answer by Kurdle_4855 · Feb 18, 2016 at 08:44 AM

You could have a Box Collider Trigger around the 'Mountain' terrain and when you enter the trigger you can't build, but when you exit you can build again. This probably wouldn't be the best for extremely large terrains though(exceeding 10 x 10 km or 100sq km)

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 terraKote · Feb 24, 2017 at 06:35 PM 0
Share

I think this solution is the best. I've encountered with similar question before, and using triggers may be very helpful. I wrote a class for such needs which had information about the zone itself and presence of player in it. To make it easier to organize, you can use gizmos to display the zone on your terrain.

avatar image
5

Answer by b1gry4n · Aug 31, 2016 at 07:47 AM

Depending on how "mountainy" your mountains are and how "flat" your flat land is, you could always just do a hit.normal angle check. If the angle is above x, the player cant build

http://answers.unity3d.com/questions/377506/how-i-can-know-surface-angle.html

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
2

Answer by amelnik · Jan 04, 2014 at 10:16 PM

If your regions are of geometrical shapes like cylinder, cube, sphere, circle or rectangle it would be quite easy. You'd need to use points in the inspector and a class that will be able to check if something is in the region: public class Region : MonoBehavior { public ArrayList pointsArray;

   public bool IsInArea(Vector3 v)
   {
      //Do mathematic calculation on v and the position on the points, returning whatever v is in the area or not.
   }
 //all of this is untested and theoretical code
 }

The mathematical calculation is: Box/Cube/Rectangle/Square - Get 2 points, at the opposite sides of the shape. Check if v's x,y,z values are between the values of the points. Sphere - Get 1 point and a radius, and check the Vector3.Distance() between v and the point. If the distance is smaller than the radius, it's in the sphere. Circle - Like sphere, but with Vector2s and only the x and z axes.

Other solution, that is probably easier: Add a collider component to your terrain, and make it trigger. the collider should be the shape you want your region. If you want irregular shaped region, make it a mesh collider with a mesh the shape of your zone (probably not practical to you). In a script attached to the object you can then write a method named OnTriggerEnter(Collider other) and in it write code to do when an object enters the region.

I hope at least one of the solutions help. Good luck.

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

21 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

Related Questions

Multiple Cars not working 1 Answer

[BEGINNER] Generating Terrain with Perlin noise flat and nothing happens ? 1 Answer

copy smaller size terrain's data, and seet the heights on bigger Terrain at click position 0 Answers

My VR game build crashes when the terrain is enabled. 0 Answers

Build error when using BooleanOps.dll 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