- Home /
SphereCastAll doesn't works
Hi, I'm trying to use a sherecast but I've some problems... My scene is just a cube and a sphere. The sphere is a moving object and it should get the cube's collider when it's in range.
void Update ()
{
Vector3 pos = transform.position;
pos.x += Mathf.Lerp(Time.deltaTime,defaultX,defaultX - 10.0f);
transform.position = pos;
RaycastHit[] hits = Physics.SphereCastAll(transform.position,radius,transform.right,0.0f);
foreach(RaycastHit hit in hits)
{
print("Hit: " + hit.collider.name);
}
}
The cube has a collider that is NOT a trigger (according to the documentation). I'm expect to get the cube hitted by the spherecast but it doesn't happen. Any ideas?
Cheers
Answer by hoffmanuel · Oct 29, 2012 at 12:53 PM
have you tried altering the last parameter of the SphereCastAll function to a non-zero value?
eg:
Physics.SphereCastAll(transform.position,radius,transform.right,radius);
the last parameter should mark the distance property to the function. give it a try :)
That way you're moving the sphere along the x axis. I tried but doesn't work. $$anonymous$$aybe should I enable some setting somewhere?
Your answer
Follow this Question
Related Questions
Make a capsule collider BETWEEN 2 objects 0 Answers
How to use a Raycast to see the distance traveled within a collider. 2 Answers
Move player to specific location and avoid obstacle. 2 Answers
Im trying to create a word game with a twist 0 Answers
Raycast not detecting ANY HITS AT ALL when starting inside a collider. 0 Answers