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 LegionIsTaken · Jul 22, 2011 at 08:34 PM · instantiateterraintriggers

Detecting what parts of the terrain was hit.

Hi.

In my game I have a terrain. I also have guns that fires using raycast and I would like to Instantiate different particles at hit.point of the raycast. But since I am dealing with a terrain how do I distinguish wheater or not I am shooting grass, sand or rock painted on the terrain?

If you get what I mean.

Sorry this is a little hastly written bacause I have to hurry out the door. If this has not been answered when I come back I will re-formulate my self.

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

Answer by Owen-Reynolds · Jul 23, 2011 at 01:38 AM

This comes from tested code, but I may have tweaked it and broken it. In my particular case, I'm checking a transform named puffPose, and grass is texture #5, which is [0,0,4]:

 // Set up:
 Vector3 TS; // terrain size
 Vector2 AS; // control texture size
 
 TS = Terrain.activeTerrain.terrainData.size;
 AS.x = Terrain.activeTerrain.terrainData.alphamapWidth;
 AS.y = Terrain.activeTerrain.terrainData.alphamapHeight;

 
 // Lookup texture we are standing on:
 int AX = (int)((puffPos.x/TS.x)*AS.x+0.5f);
 int AY = (int)((puffPos.z/TS.z)*AS.y+0.5f);
 float[,,] TerrCntrl = Terrain.activeTerrain.terrainData.GetAlphamaps(AX, AY,1 ,1);
 // This can get a grid. Since we are only getting 1, we have a 1x1 array
 // The 3rd is the 0-1 weight of that texture (if you have 4 textures, the 3rd
 //   has size 4. TerrCntrl[0,0,0] is the weigth of texture#0.)
 // TC[0,0, 0-??] add to 1
 float c1=TerrCntrl[0,0,4];
 if(c1>0.5f) ....  // grass is 50% or more in this area
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 Chris D · Jul 22, 2011 at 09:03 PM

I think you would just be after the Splat Texture and then go from there. What I'm unsure about is how you distinguish which texture is applied to a particular spot on the terrain; the property returns an array, but I'm not familiar enough with TerrainData to know how to use that properly... Maybe someone else can offer some insight on that.

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Instantiate trees on terrain with perfect height. 2 Answers

Making a particle effect parallel to the slope of a terrain 1 Answer

Make an instantiated object match the slope of the terrain 1 Answer

How can I clone a Terrain object? (Not the reference) 1 Answer

Quickest most efficient way of instantiating a large amount of GameObjects 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