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 jamesw_unity731 · Apr 20, 2018 at 04:54 AM · raycastoverlapspherespherecast

SphereCast misses but RayCast and OverlapSphere don't

I'm brand new to game dev so bear with me.

code in question:

 Debug.DrawRay(controller.Eyes.position, controller.Eyes.forward.normalized * controller.Stats.LookRange, Color.green);
 
             var overlappingColliders = Physics.OverlapSphere(controller.Eyes.position, controller.Stats.LookSphereCastRadius);
             var rayCastResult = Physics.Raycast(controller.Eyes.position, controller.Eyes.forward.normalized, controller.Stats.LookRange);
 
             var sphereCastResult = Physics.SphereCast(
                 controller.Eyes.position,
                 controller.Stats.LookSphereCastRadius,
                 controller.Eyes.forward.normalized,
                 out hit,
                 controller.Stats.LookRange);
             if (sphereCastResult
                 && hit.collider.CompareTag(
                     (controller.TeamTag == Tags.BlueTeam)
                         ? Tags.RedTeam
                         : Tags.BlueTeam))
             {
                 // we see a target that is not on my team
                 controller.CurrentTarget = hit.transform;
                 return true;
             }

This is pulled from the "PluggableAI" tutorial and works in that project, but not in my project.
I expect my object to see a Cube Collider. I can see it hitting it with Debug.DrawRay. RayCast returns true and OverlapSphere shows the collider as well. So why does SphereCast pass straight through that collider and continue on all the way to the "South Wall" collider a long way across the map?

Missing the collider with SphereCast

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
1
Best Answer

Answer by Cornelis-de-Jager · Apr 20, 2018 at 04:59 AM

Hi mate, I think the issue is with your

 && hit.collider.CompareTag(
                      (controller.TeamTag == Tags.BlueTeam)
                          ? Tags.RedTeam
                          : Tags.BlueTeam)

try removing that and see if the Spherecast hits then. Because It looks like it should.

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 jamesw_unity731 · Apr 20, 2018 at 01:01 PM 0
Share

I thought so too which is why I moved the sphereCastResult to it's own line outside the original If statement.
If you look at line 12 if (sphereCastResult that value for sphereCastResult is already false so the tag check doesn't interfere at all.

avatar image jamesw_unity731 · Apr 20, 2018 at 09:55 PM 0
Share

Well....turns out you were right. It also turns out the code I pasted above wasn't exactly what I was working with at the time. I apologize for that.

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

111 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 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

How to scan a surface of a GameObject and get the distance of every edge to camera 1 Answer

Should Items spherecast 0 Answers

How to Spherecast/Raycast diagonally? 1 Answer

Problem Standing into Objects 0 Answers

Generating lines between procedurally instantiated gameobjects, within a certain radius 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