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 /
  • Help Room /
avatar image
3
Question by SuperRaed · Sep 21, 2016 at 01:05 PM · spherecastspherecastall

Why does a SphereCast require a direction, shouldn't a sphere be in all directions? and how to cast a sphere around my object from it's center in all directions

I'm trying to capture Raycast hits; to get the normal of the objects around my player as in the picture. I've been using Physics.spherecast but its behaving as if it's a Raycast, that is it's capturing Hits in the given direction.
alt text

spherecast.png (5.5 kB)
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

3 Replies

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

Answer by WillNode · Sep 21, 2016 at 01:54 PM

I'm sure that this is what you're looking for : Physics.OverlapSphere

SphereCast is like a ray, but with thickness along the ray with given radius (like a capsule).

EDIT: SphereCast still does what you wanted. It's parameter may seems confusing, but you can put the direction into Vector3.zero to get a perfect spherical shape. Don't this is what you meant?

Comment
Add comment · Show 5 · 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 SuperRaed · Sep 21, 2016 at 04:03 PM 0
Share

Overlap sphere is working fine, with the exception of one thing. it doesn't get me a RaycastHit which I need to find the surface normal, it returns a collider ins$$anonymous$$d, any ideas how to get the normal or a Raycasthit from a collider?

avatar image WillNode SuperRaed · Sep 21, 2016 at 08:00 PM 0
Share

Okay, updated my answer. If you need those RaycastHit

avatar image NoseKills · Sep 22, 2016 at 06:55 AM 1
Share

shouldn't a sphere be in all directions?

Yes. But spherecast moves a sphere through the world in certain direction and certain distance and sees what it hits on its way.

put the direction into Vector3.zero

or at least the distance as 0.

avatar image rhodnius · Apr 08, 2020 at 05:21 PM 0
Share

Setting direction to Vector3.zero does not work for me

avatar image PitaBreadGames · Dec 23, 2020 at 10:59 AM 1
Share

This should not be the accepted answer.

OverlapSphere is great when you just need to know what you hit but no hit info (i.e. normal, hit point, distance, etc.). This is not what the OP needed.

SphereCast only returns a hit info after it has moved. A SphereCast with a direction of Vector3.zero will not return a hit even if it should.

I recommend looking at advo's answer for more detail.

avatar image
5

Answer by advo · Apr 28, 2020 at 05:14 PM

Guys i ran into similar problems and here is what I found.

Setting "direction" as Vector3.zero just caused the Spherecast to not work regardless of "maxDistance".

Setting "direction" as the forward direction (e.g. transform.forward), and setting the maxDistance of a small value example 0.1f, worked.

In my testing,the Spherecast only picks up collisions that happen at the "front half" surface of the Sphere, front being the "direction" that the "Sphere" being casted. Hence if you were to have an enemy facing the positive Z direction and constantly casting a SphereCast of maxDistance of 0.1f (or any maxDistance) in the forward direction, you will notice that a hit is only registered when a collider intersects with the front half surface of the Sphere.

If you move a collider into the sphere from the rear half, it does not register the collision. It does not detect collisions in the rear half of the Sphere, or anything that is already "inside" the Sphere.

Think of the the Spherecast being more of a U-shaped "Sonic Boom" shape cast by Guile from Street Fighter.

Which also means if your "origin" parameter of the Spherecast call, fell right smack on a small target that you intended the cast to collide with, and if your sphere radius is larger than the target collider, you might not actually register a hit...

public static bool SphereCast(Vector3 origin, float radius, Vector3 direction, out RaycastHit hitInfo, float maxDistance = Mathf.Infinity, int layerMask = DefaultRaycastLayers, QueryTriggerInteraction queryTriggerInteraction = QueryTriggerInteraction.UseGlobal);

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
2

Answer by Bonfire-Boy · Sep 21, 2016 at 01:54 PM

That's what sphere cast does. From the documentation, "Think of the sphere cast like a thick raycast."

https://docs.unity3d.com/ScriptReference/Physics.SphereCast.html

You might want to look at OverlapSphere as an alternative

https://docs.unity3d.com/ScriptReference/Physics.OverlapSphere.html

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 SuperRaed · Sep 21, 2016 at 04:02 PM 0
Share

Overlap sphere is working fine, with the exception of one thing. it doesn't get me a RaycastHit which I need to find the surface normal, it returns a collider ins$$anonymous$$d, any ideas how to get the normal from a collider?

avatar image Bonfire-Boy SuperRaed · Sep 21, 2016 at 04:18 PM 1
Share

Hmm. so what you actually want is a RayCast that sends rays in every direction. That would be quite expensive. Someone else may have a better idea but the first thing that springs to my $$anonymous$$d is to use OverlapSphere to get a list of candidates and then RayCast at each of them individually to get a contact point etc (or SphereCast, with the size deter$$anonymous$$ed by the size of the candidate).

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

59 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

SphereCastAll hit.point are allways zero 1 Answer

The SphereCastAll is not picking up certain objects 1 Answer

AI and Enemy Detection 1 Answer

Having Troubles with Sphere Casts 0 Answers

SphereCast ignores new terrain colliders? 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