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 DayyanSisson · Sep 04, 2012 at 03:51 AM · raycastcolliderterrainraycasthitwater

Raycasting Through Terrain

I need to check to see if an object is about to walk into water. What I need the object to do is turn around so it doesn't walk into it. I've set up a water collider just below the water itself, and I have it so the object is raycasting to the ground slightly in front of him. Unfortunately, since the water collider runs under the terrain, even if the object is on the terrain and the raycast doesn't hit any visible water, it raycasts through the terrain to the water below, and the AI keeps reacting like its about to run into the water. Why is that, and how should I fix it?

Comment
Add comment · Show 5
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 Fattie · Sep 04, 2012 at 04:40 AM 1
Share

it's possible the physics LAYERS system is what you need here.

avatar image Anusha · Sep 04, 2012 at 08:53 AM 0
Share

wont setting the collider above the water work?? or just surronding it... so that when object approaches the water it trrigers??

avatar image Fattie · Sep 04, 2012 at 09:16 AM 0
Share

Anusha .. not really, that would just cause other problems. the only way to use a physics engine is to understand and use the physics "layers" system. there's no other way to get work done!

your english is great BTW !

avatar image Anusha · Sep 04, 2012 at 09:59 AM 0
Share

i know this is none of my business...but i just cant figure out how to use layer in this case... @Fattie could you please just give me a rough idea. or maybe @Overlord if you have solved this issue could u let me know how you did it? please

avatar image DayyanSisson · Sep 05, 2012 at 01:55 AM 0
Share

Even if I used layers, the raycast would go through the terrain and still hit the water.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by PProductions · Sep 04, 2012 at 01:52 PM

Raycasting every frame is not efficient. Simply make the water collider a trigger and use something like the following code to check the collision:

 function OnTriggerEnter(object : Collider) {
     if(object.tag == "Water") {
         //turning code
     }
 }

Just set up your water collider to have the tag 'Water'. this is the technique used by 'Burg Zerg Arcade' in his video tutorial : Video Tutorial

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 DayyanSisson · Sep 05, 2012 at 01:50 AM 0
Share

Thats not the problem. The object has to stop well before it reaches the water which is why it raycasts on the ground in front of it, not below it.

avatar image PProductions · Sep 05, 2012 at 03:09 PM 0
Share

Perhaps set the collider a little higher?

avatar image DayyanSisson · Sep 06, 2012 at 12:06 AM 0
Share

No the problem isn't that its not hitting the water collider. The problem is that it is even when the raycast should just hit the terrain.....which it doesn't. I don't want it to raycast through the terrain. Is that just how Raycasting works? Just ignore the terrain collider? Cause I do have several other scripts where I encounter the problem of it ignoring the terrain hit and passing right through it.

avatar image jacupiri · Sep 10, 2016 at 10:45 PM 0
Share

I'm having the same issue. The Raycast ignores the terrain and, as a consequence, my NPCs go right through it, until they reach the terrains lowest height.

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

10 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

Related Questions

How do I check for collisions when I move objects based on Time.deltaTime? 3 Answers

Raycast problem trough the terrain 1 Answer

Using raycast and collider to increase int 1 Answer

Need Help with RayCast. No Vector? 1 Answer

RaycastHit: What is the difference between hit.transform.tag and hit.collider.tag and which should I use when? 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