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 mehow · Mar 21, 2014 at 12:06 PM · terrainraycastingbuildingterraincollider

How to restrict building on uneven surfaces?

I have been looking all over the place for any information regarding building objects on uneven surfaces / restricting the area to build / ie. building a turret only in designated places on a 3D map...

for instance have a quick look at the below screenshots alt text alt text

The red is for enemies path as well as mountains.

Now what technique do I use to restrict the building of turrets in certain places? Do I need to write my own custom class based raycast and pretty much hard code the dimensions ??

I will appreciate any informations and insights on how to go about it. Thanks for your time.

p1.png (122.2 kB)
p2.png (165.5 kB)
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
2
Best Answer

Answer by whydoidoit · Mar 21, 2014 at 12:10 PM

So you can get the height map as an array of floats. if you are free form placing buildings I would suggest testing these floats for 16 positions (could be more or less based on your scale I guess) representing the rectangle that is the floor plan of your turret - if they are all the same height then allow building.

Alternatively, scan the map in an editor script and and for each location specify the largest rectangular area that can be built at that point by doing the same thing as above, but scanning every float, store this as either a square size in an array or a pair of max width and max height. Then when you go to build something, lookup the closest location in the array and check whether your turret would fit in this space, update the arrays to indicate that further building is not possible for the dimensions of the thing you've put there or alternatively use OverlapSphere with a layer mask ignoring the terrain to see if anything is in the way.

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 mehow · Mar 21, 2014 at 12:27 PM 0
Share

thanks for your answer. Can you please elaborate on the height map as an array of floats? Do you by any chance have any tutorials or references I could use for this?

avatar image Fornoreason1000 · Mar 21, 2014 at 12:30 PM 0
Share

height maps as an array of floats, basically your getting the height data from the terrain and converting into a 2 dimensional array of numbers with each number representing a level of height on the terrain.

avatar image whydoidoit · Mar 21, 2014 at 12:33 PM 0
Share

You use Terrain.activeTerrain.terrainData to get to the root of the terrain info and then use GetHeights to retrieve the array of floating point heights.

avatar image
2

Answer by Owen-Reynolds · Mar 21, 2014 at 03:35 PM

The traditional way to do this is to put an invisible grid on the map, and hand-mark each legal space. Hand-mark, since maybe you have a space that's flat enough, but is quick-sand, or you just want to be sure it's always clear. Every game where you can tell each building is 2x2, or 3x3 "grid squares" does it this way.

WhyDoIDoIt writes "if you are free form placing buildings." And the advice on how to accomplish that seems fine. But look back at your inspiration. Does it let you move a tower 8-1/2 inches to the left? Do you want that?

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 mehow · Mar 24, 2014 at 09:53 AM 0
Share

This sounds like a good idea - the invisible grid but still I can't get any tutorials or info on how to implement that :/

avatar image whydoidoit · Mar 24, 2014 at 11:21 AM 0
Share

Agreed that's a good way to go on predefined maps - however, given the resolution of a terrain you will never get the 8 1/2 inches scenario, would be significantly larger areas than that unless the terrain was very small with a high resolution.

Dynamically/procedurally created terrain can also benefit from sampling the splat map to ensure that the surface is suitable for building.

avatar image mehow · Mar 24, 2014 at 11:28 AM 0
Share

https://www.youtube.com/watch?v=p$$anonymous$$RnfwFOc_c @ 9:25 see that grid, this is pretty much what I would like but I literally have no idea how to implement it. Any advice?

avatar image Owen-Reynolds · Mar 24, 2014 at 03:04 PM 0
Share

Suppose you decide a 200x200 meter map should be treated as a 50x50 grid. $$anonymous$$ake a 50x50 array. Could be transforms, pointing the the placed item, and null means free, or could be a class you write "gridSpace." If you don't know arrays, this will be tricky.

Each grid space is 4x4 meters. So the equation for map-to-grid is x/4, round down (same for y.) Grid to map is x*4+2 (the +2 goes to the center of the square.)

A cheap way to see the grid is make a single line square texture, put on a 200x200 plane, then tiled 50x50.

8-1/2 inches: the real question is, will you ever want to adjust the tower by a tiny amount -- a little better cover, little more range? Seems like you would, but lots of games clearly have 2x2 cannons, and you can only move by 1/2 a cannon.

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

Terrain Generation ruins collision 1 Answer

Terrain trough floor. 1 Answer

Terrain collider - add 2 Answers

How to make a raycast follow terrain? 1 Answer

Starforge type gameplay 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