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
1
Question by shawnlehner · Jan 14, 2011 at 01:30 AM · physics

What is the proper usage of SphereCast

I am having some trouble getting Physics.SphereCast to work as I expect. My reason for using this method is to get some extra "padding" around my standard mouse raycast for touch input.

The following code snippet works just fine:

          RaycastHit hit;
            if (!Framework.IsMouseBlocked &&
                Physics.Raycast(Framework.MouseRay, out hit, 1000, (1 << 8)))
                m_hover_object = (Decoration)hit.transform.GetComponent(typeof(Decoration));
            else
                m_hover_object = null;

This code does not work however:

            RaycastHit hit;
            if (Physics.SphereCast(Framework.MouseRay.origin, 15, Framework.MouseRay.direction, out hit, 1000))
                m_hover_object = hit.transform.GetComponent<Decoration>();
            else
                m_hover_object = null;

The purpose for using the orgin/direction override of SphereCast was just to test and see if I got a different result. My initial attempt was using the Ray override for the method, this also failed.

The selection never returns any results even when used in situations where the RayCast does.

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

Answer by Jessy · Jan 14, 2011 at 02:01 AM

Looks good to me, but I don't know what Framework.MouseRay.origin or .direction are. My initial thought is that your radius is too large. If the sphere is so fat that it's already colliding, and no other colliders exist in that direction, it will return false.

If that's not helpful, test without your custom data, because your methodology is sound.

Comment
Add comment · Show 7 · 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 shawnlehner · Jan 14, 2011 at 05:46 AM 0
Share

There is something wrong with the way the current implementation is working. I will submit a support ticket tomorrow when I have more time.

Here is an overview of my setup and what is going wrong:

I have a game object with a box collider marked as trigger and a rigid body with gravity disabled and collision detection mode set to discrete. This object begins its life disabled and is enabled later in the scene. At this point the collision detection using SphereCast does NOT work, RayCast does.

To get the collision to work I perform the following steps in editor: 1) Uncheck the "Is Trigger" op

avatar image shawnlehner · Jan 14, 2011 at 05:46 AM 0
Share

To get the collision to work I perform the following steps in editor: 1) Uncheck the "Is Trigger" option on the collider. 2) Switch the collision detection mode to "Continuous Dynamic" 3) Switch the collision detection mode back to "Discrete" 4) Check the "Is Trigger" option back on the collider 5) The collision using SphereCast is now working!

avatar image Jessy · Jan 14, 2011 at 06:32 AM 0
Share

I just reported a bug, and then saw this. I will add this workaround to the bug report; thank you. http://answers.unity3d.com/questions/36479/physics-capsulecastall-not-detecting-kinematictrigger-colliders/36480#36480

avatar image shawnlehner · Jan 14, 2011 at 05:50 PM 0
Share

Thanks for reporting the bug Jessy, looks like I will use a few Physics.OverlapSphere() checks ins$$anonymous$$d for the time being. I am really thankful that they are adding so many more features to the Physics system though, I look forward to future updates!

avatar image shawnlehner · Jan 15, 2011 at 03:49 PM 0
Share

Should I mark this as the answer since it offers some form of resolution to the problem? Or should I leave it open since the problem is not "solved"? I am more of a forum guy myself, I don't know the proper answers etiquette =)

Show more comments

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

No one has followed this question yet.

Related Questions

2D 360 degress platformer example needed 0 Answers

How to implement a simple top-down racing game in 3D environment? 1 Answer

How to use 2D box colliders with out Rigidbody2D 0 Answers

Accelerate a rigidbody towards max speed 2 Answers

slowing sideways velocity 2 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