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 Persona · Nov 03, 2010 at 04:15 PM · rayexplain

Understanding Spherecasting

I need to learn how to use sphere casting and looked up the reference, but there are parts I don't understand, like the charcontrol, p1 and p2. Can anyone explain how to use it to set up various ranges?

http://unity3d.com/support/documentation/ScriptReference/Physics.SphereCast.html

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 Adam Rademacher · Nov 03, 2010 at 04:36 PM

The scripting reference is for a capsulecast but it's very similar. P1 is the center of the sphere. They calculate it as the gameobject's position + the center of the character controller - half the height of the character controller (this should get you basically the center of the 'charactercontroller' component). P2 is for capsulecasting (the height of the capsule), so omit it from your script. Radius is just the radius of the sphere that you want to cast (1, 2, 8, etc.), then distance is how far the sphere will cast, and it will out hitinfo if it hits anything.

Physics.SphereCast(new Vector3(0,0,0), 2.0f, Vector3.forward, hit, Mathf.Infinity);

Would cast a sphere from the origin of the world forward (along the global Z) with radius 2 for infinity and return hitinfo for what it hits.

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 Persona · Nov 03, 2010 at 04:58 PM 0
Share

I keep getting an error saying: Assets/Scripts/Sphere Cast.js(10,13): BCE0019: 'SphereCast' is not a member of 'UnityEngine.Physics'.

avatar image Persona · Nov 03, 2010 at 05:30 PM 0
Share

It must've been because I was running unity 2.6.

avatar image Adam Rademacher · Nov 03, 2010 at 09:00 PM 0
Share

Spherecast was added in Unity 3. You'll have to use CapsuleCast to simulate a spherecast ins$$anonymous$$d.

avatar image BlackPanda · Mar 08, 2014 at 08:40 AM 0
Share

Thanks Adam, but whats the difference between the arguments radius and distance?? Aren't they the same??

avatar image whydoidoit · Mar 08, 2014 at 09:45 AM 0
Share

No, the radius is the radius of the sphere which is then cast a long a line of the length indicated by distance

avatar image
4

Answer by Adam-Buckner · Mar 30, 2011 at 07:43 AM

I'm posting this here in "Understanding Spherecasting" as I have discovered when researching Physics.SphereCast that most people mis-understand spherecasting and want it to do something other than it's intended for. Moreover, the Unity documentation is typically under-descriptive.

I've posted my documentational bug-report, additional information and a descriptive image here: http://theantranch.com/Unity/Unity.html

In a nut-shell:

Spherecasting is designed to cast a "thick ray" by sending a sphere of size (origin, radius) down a ray (origin, direction, length) and returns an array of raycastHits: raycastHit[] (out hitInfo) that collides with the sphere if they are both on the correct layers (layerMask).

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 GaRzY · Oct 28, 2013 at 04:39 PM 0
Share

Adam, thanks for your explanation, I was confused but now I understand perfectly!! Great!!

avatar image
3

Answer by StephanK · Nov 03, 2010 at 04:30 PM

The example in the documentation is wrong. It uses a capsule cast not a spherecast. For spherecasts you don't need p1 and p2. p1 would be enough and should be the position where you want to start the raycast.

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 Pugschnizzle · Oct 10, 2014 at 05:46 PM

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

might be what some people are looking for

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

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

Raycasting to turn varible on and OFF 1 Answer

How to import the object from server to unity 2 Answers

Getting the Furthest Point on a Ray 1 Answer

WorldToScreenPoint / Rays with stereoscopic 3D 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