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 /
This post has been wikified, any user with enough reputation can edit it.
avatar image
0
Question by michele · Oct 31, 2010 at 03:08 AM · transformcentershift

SphereCast casts from the circumference, not the center of the sphere

Is this behaviour of Physics.SphereCast correct? I mean, it seems that SphereCast casts starting from the circumference, not the center of the sphere.

For example if you add a sphere to a game object and try this code

using UnityEngine;

public class test : MonoBehaviour {

public bool onGroundDown=false; public bool onGroundLat=false; public bool onGroundFront=false; public bool onGroundRear=false; public float width =0.8f; Vector3 sphereCenter;
RaycastHit hit;

void FixedUpdate(){ sphereCenter=transform.position; onGroundDown = Physics.SphereCast(sphereCenter, radius, -transform.up , out hit, radius); onGroundLat = Physics.SphereCast(sphereCenter, radius, transform.right , out hit, radius); onGroundFront = Physics.SphereCast(sphereCenter, radius, transform.forward , out hit, radius); onGroundRear = Physics.SphereCast(sphereCenter, radius, -transform.forward , out hit, radius); }

}

you obtain this result:

alt text

Since i want to find all the contact points of a sphere (without using a collider) is there a way to do this using spherecast? To be clear, i want to do something like this:

http://newtondynamics.com/forum/viewtopic.php?f=14&t=5999

UPDATE 11/10/2010 corrected the esposition

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
2
Best Answer Wiki

Answer by skovacs1 · Nov 09, 2010 at 08:34 PM

There are several things wrong with this question:

  1. Spherecast's center is the center that you specify. Of course it's center is different from the transform's center. It has nothing to do with the transform center unless you pass the transform's center as the center of the spherecast when you call it.

  2. You assume that the transform position is at the center of the object when it may not be. The transform's position is wherever the pivot is located. It could be below, on top of or even 1000000 units on the x axis away from the center of the object.

  3. Physics.Spherecast works exactly as it should. You provide a center point, a radius, a direction to move, (optionally a RaycastHit,) and a distance to sweep. The Physics will move the sphere of the radius provided in the direction provided by the distance provided and if there is a collision, it will return true. Otherwise it will return false.

Whatever it is that you consider "expected behaviour" seems to be mistaken. Perhaps you should explain what it is that you expect to happen. A sphere of radius 0.5 cast a distance of 0.5 in a direction should hit any colliders whose exteriors are positioned between position 0.5 and 1.0 on that axis and whose exteriors are facing the object.

This is what your spherecast is doing:

____ _ _ _ / \ \ | 0.5|-0.5->| ____/_ _ _ / |---1.0---|

//contact points are the first points at which colliders within the //sweep area touched the sphere being swept

Comment
Add comment · Show 9 · 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 michele · Nov 10, 2010 at 01:58 PM 0
Share

I explain better what i want to do. I want to use spherecast to check if a sphere collide with anything. So this is what i do:

1)add an empty game object 2)add a sphere collider with isTrigger checked (radius 0.5 center (0,0,0) so pivot coincide with the center of the tranform). the collider is not used,its just to have a visual repr. of the sphere 3)add the code above 4)I expect that i can check if the sphere collides with anything via the various onGroundDown, onGroundLat, onGroundFront.

But it doenst work.its like the spherecast is always "shifted" respect the sphere collider.

avatar image skovacs1 · Nov 10, 2010 at 04:44 PM 0
Share

A spherecast will sweep a sphere through 3D space. That's what the distance parameter is for. You are providing a distance of radius so it will sweep radius units in the direction that you provided. If you didn't want it to sweep, you could provide a distance of 0, but why use Spherecast in this case? If you don't want it to sweep, why not just use OverlapSphere or CheckSphere?

avatar image michele · Nov 10, 2010 at 08:49 PM 0
Share

I do want to do a sweep test. Im using the spherecast to find all the contact points of a wheel, for this reason im using a spherecast (raycast doesnt find all the contact point). So i put the wheel at the center of the transform and i do a spherecast from the center of the transform with radius the radius of the wheel (and lenght of the sweep radius). So I EXPECT that with onGroundDown, onGroundLat, onGroundFront i can find all the contact point of the wheel, but it always casts starting from the circumference, not the center of the sphere.

avatar image skovacs1 · Nov 12, 2010 at 03:33 PM 0
Share

Spherecast does a sweep because that's what it's supposed to do. As I said before, if you do not want a sweep, then you shouldn't provide it a sweep distance when you call it. It does not cast starting from the circumference! It starts from the center you passed in and then sweeps a sphere of the radius you passed in by the distance you passed in along the direction you passed in because that's what a spherecast is.

avatar image skovacs1 · Nov 12, 2010 at 03:34 PM 0
Share

If your problem is that your tire is already in contact with the ground when you cast and the cast is not picking up the contact, you should consider passing spherecast a radius that is slighly smaller than your tire so that the ground is not already inside of the sphere that is being cast.

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

Physics.SphereCast problem? center of SphereCast different from center of its transform 0 Answers

How do I offset the scaling center for a cube 1 Answer

Finding the center of several GameObjects 1 Answer

The gizmo is not at center of object 0 Answers

Instantiated Game Object is at the wrong location. 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