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 SomeRandomGuy · Jul 16, 2012 at 11:49 AM · 2d3ddistanceradiusspherecast

resizing spherecast radius over distance?

Hi, I am using a spherecast to detect if there is something in front of me, but only want it to "see" anything within a certain screenspace. Doing this works fine, but doesn't when too close or too far from the object, as I am checking in 3D, not in 2D screenspace.

So what I'd like to do is change the sphere's radius according to the distance it travels. I am not sure whether this is possible or not, or if I should simply start over.

Any input is highly appreciated!

Thanks in advance,

~Nick

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

4 Replies

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by senad · Jul 16, 2012 at 02:34 PM

I do not think you can achieve this with the sphere cast, because it will search in a constant tunnel around the search ray. This tunnel will become smaller in screen space with distance.

However, if you shoot some rays from the eye point through the bounds of your search area (in screen space), those rays will drift apart when moving further away. This way, your searching volume will always have the same size in the screen. Now you will have the problem that as the rays divert from each other, there is more room to miss objects, so maybe you will need in-between sampling rays, which is bad for performance. How well this works depends a lot on your geometry.

Another way would be to project all objects in the view frustum onto the viewing plane and check in screen space if they intersect with your search area. However, this only makes sense performance-wise, if there are not many objects.

There might be also easier solutions. And I whish I could draw it, it would be much easier to understand. :D

Comment
Add comment · Show 2 · 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 SomeRandomGuy · Jul 16, 2012 at 03:07 PM 0
Share

Hmm didn't think about sending a ray from the middle to the bounds, tho this is basically the same thing as I was trying to achieve using a growing spherecast of some sort. But I guess I'll be better off just getting a list of visible objects, then checking if they are within my searching area. might not be the best way to do stuff, but I doubt the way I'm doing it now is any better, haha!

avatar image senad · Jul 16, 2012 at 03:24 PM 0
Share

Actually, setting up a second camera to test against a smaller view frustum might be what you need. That is if you can accept a rectangular seach area.

avatar image
1

Answer by senad · Jul 16, 2012 at 02:37 PM

Oh and another idea would be to render all your geometry in an extra render pass with the stencil buffer enabled and set up the stencil buffer to only render the geometry which will lie in your defined search 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
1

Answer by flaviusxvii · Jul 16, 2012 at 02:48 PM

I think you are talking about testing against the view frustum.

https://www.google.com/search?q=camera%20frustum&bav=on.2,or.r_gc.r_pw.r_qf.,cf.osb&biw=1814&bih=858&um=1&ie=UTF-8&hl=en&tbm=isch&source=og&sa=N&tab=wi&ei=kikEUMm8JuHq2AWxx729Cw

Here are several ways to do this.

http://answers.unity3d.com/questions/8003/how-can-i-know-if-a-gameobject-is-seen-by-a-partic.html

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 SomeRandomGuy · Jul 16, 2012 at 03:13 PM 0
Share

yes, I suppose I was sort of trying to create a fake view frustum for my spherecast if you will. had a look at the link, and I think I'll figure something out using the suggestions in there, thanks! :D

avatar image
1

Answer by MikeTheMonster · May 06, 2020 at 11:49 AM

Late anwser , but maybe this helps someone. You can use SphereCast and thereafter check the angle of the returned collider to see if it would have fit inside a cone. The radius of the sphere should be the radius of the cone's base and the distance of the cast, the height of the cone. Use Mathf.Asin(radius/height) to determine the angle you want to check and Vector3.AngleBetween to get the angle of the point relative your gameobject.


I think it would be cheaper to have a capsule collider and then use the suggested code within the OnTriggerStay event. Then you would need to cast a ray to the obect to check for obstruction.


This post was inspired by walterellisfun's ConeCast extension method. https://github.com/walterellisfun/ConeCast

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 Surya-Vamsi · Jan 30, 2021 at 08:05 PM 0
Share

You are GENIUS my friend <3

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

8 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Drag n Drop in a 3D orthographic environment 1 Answer

How do I make a 2D character/npc follow the player using texture offsetting 0 Answers

Sprite quality decreased after adding 3d object to 2d game 0 Answers

Szise is wrong in build 2 Answers

I can only view my objects in 2d mode??? 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