- Home /
Problem in spherecast .
Hello Guys , I used spherecast and it was working fine . But, suddenly , i found out that it gives null RaycastHit if am in collision with object or near to it .
Physics.SphereCast( transform.position + char_Controller.center, char_Controller.height / 2, Vector3.forward, hit, 1);
Does it mean that object is in between object and spherecast , and in this situation sphercast did not collide with object????
http://www.theantranch.com/Unity/Entries/2011/3/29_Understanding_Spherecasts_in_Unity.html
I got some info from the above site . Through above link , i think that if SphereCast overlap another collider or another collider is in the SphereCast then SphereCast returns False. But , I like to know if this is true .
um... Spherecast doesn't have a RaycastHit out. It has a RaycastHit[] out
Answer by sparkzbarca · May 20, 2013 at 01:52 AM
its giving a null because it didn't collide with it because it's inside it.
You shouldn't use controller height you should use the radius of the controller collider.
basically assuming a normal human yfor the character you ahve a 6 foot (2 meter human)
its height / 2 is 1 meter.
however its width is far less than that, i'm alot thinner than my height (a radius is from center to edge, its only half the diamter, this is a circle that is 6 feet from one side to the other, a huge sphere for a collision check your doing no doubt)
so something touching my nose/belly/foot is closer than 3 feet from the center of my body.
basically you need to make your radius equal to the radius of the collider attached to your character controller which if we do some basic math.
a 40 inch waist should not have a 1 meter radius but a .1524 meter radius
set your radius to .1 (thats point 1 by the way not just 1) and try it. Then set it to the radius of the actual character controller at some point. :P