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 oliver-jones · Mar 31, 2011 at 12:27 PM · textureterraindetection

Detect Different Terrain Texture?

Hello,

I have a simple tower defence game, with a path leading from one end of the scene, to another end - the enemy follow this path using waypoints. The user can place a turret anywhere around the scene at the moment. But is it possible not to put a turret on the path? My path uses a different terrain texture (rock) where as my 'placeable' terrain is grass - how would I tell unity not to allow the turret to be placed on anything with the texture 'rock'?

To place a turret, I use a simple raycast to determine where the user is clicking and then initiate a prefab on that position (snippet) :

function Update () { var ray = Camera.main.ScreenPointToRay (Input.mousePosition); var hit : RaycastHit; var layerMask = 1 << 8; if (chooseLocation) { layerMask = ~layerMask; Physics.Raycast (ray, hit, 500, layerMask); currentObj.Translate((Vector3(hit.point.x, currentObj.position.y, hit.point.z) - currentObj.position) * Time.deltaTime *followSpeed); } if (Input.GetButtonDown("Fire1")){ //Input.GetMouseButton(0) chooseLocation = false; // maybe a : if(terrain texture = grass? }

 // Cancel Selection \\
 if(Input.GetButtonDown("Fire2") &amp;&amp; currentObj.gameObject){
     objLimit[currentSelected] ++;
     chooseLocation = false;
     Destroy(currentObj.gameObject);
 }

}

Maybe I dont have to use terrain texture? Is there another way to do it?

Thanks folks!

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 Soviut · Apr 29, 2011 at 03:01 AM

Using the texture isn't a very good way to do it since any variation in the texture could throw the calculation off.

Instead, simply create box colliders between the waypoints that are as wide as the path. Then, when the mouse is released, check to see if the tower you're dragging is colliding with any of the boxes.

You should put the registration point on the "back" face of the box collider. This way, when you scale it, it only scales in one direction.

Next, position the box at waypoint A. Aim it at waypoint B using your favourite look at formula.

Lastly, subtract the position of A from B to get a relative vector. With this, use it's length to determine how far out to scale each box to have it touch the next waypoint.

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
1

Answer by DaveA · Mar 31, 2011 at 03:46 PM

The ray hit should give you some texture info. I've not worked with terrains that much yet, but if the color is not enough, I wonder if it's possible to have a hidden layer, or alpha channel on one that isn't, that indicates go/no-go for that.

Another way is to put invisible objects (colliders) along the ground where you don't want things and have them signal the no-go when clicked.

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

No one has followed this question yet.

Related Questions

How do I extract a texture map from a terrain? 1 Answer

Render texture is not rendering Terrain 2 Answers

Creating a Cube Projector 2 Answers

Incorporating Unity textures, models, and terrain into Eclipse 0 Answers

How to Apply Very Large Texture to Terrain 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