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 User Banned · Feb 17, 2013 at 10:37 PM · terrainplanenearestspherecastall

Detect closest reachable point of object

Evening all,

Im trying to give some level of awareness to the npc in my scene, in this case detecting where the nearest water is from its current position on the terrain. The water is a single plane stretched across the whole scene at a height of 0.

Now i believe a Physics.SphereCastAll down from above the npcs position would be a real nice solution if there were only a way of blocking the cast going through the terrain, as currently i can only ever retrieve the hit.point of the Water directly below the npc, which is obviously not cool or reachable.

  • So i suppose the question is, is there any way to block a SphereCast from passing through a collider?

  • Failing that, is there any other (or better) method to achieving my goal?

The only other method im familiar with is iterating through a stream of Terrain.SampleHeight or Physics.Raycast until Y=0, but that seems very costly for what should be just a quick scan

Any advice welcome.

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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Loius · Feb 17, 2013 at 11:27 PM

Yikes, that's a tricky one. Two options spring to mind -

Use Unity's pathfinding (I have zero experience with this) and somehow keep track of what positions are wet enough, then seek those out.

If you height-sample or raycast (down at an angle, in a circle), you can test in a sort of polka-dot pattern. Since you're looking for a body of water of some size, you can space out your tests by half of that size as you expand your search from "you", and be reasonably certain that you'll hit the closest thing. It should be easy to make the spacing large enough to make the operation pretty quick, provided it doesn't have to get called every frame.

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 User Banned · Feb 18, 2013 at 12:30 AM 0
Share

Yeah it only needs to scan the once, and SampleHeight seems to be alot faster than raycasting, so i suppose doing a scan in a spiral pattern wouldnt be too inefficient.

I also have no experience of Unitys pathfinding, but i am using arongranbergs A* and it seems its possible to "Return the nearest node to a position using the specified NNConstraint", the specified NNConstraint being editable like this, which seems like it could be an answer.

So i guess its not possible to block a spherecast with a collider? Seems a shame, functionality like that would make things like line of sight checks a doddle.

Thanks for your suggestions, got me thinking.

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

turn-base rpg navmesh, plane,terrain, scene 0 Answers

2d game foreground image based on terrain shape 0 Answers

Seamless infinte terrain 1 Answer

SampleHeight, Object refference not set to an instance of an object error 1 Answer

Character height issue 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