I am having problems with sphere cast.
I am using it to move a sphere across a scene, and if it hits a box collider move it to that location.
The problem I am having is that I can end up inside objects. This only happens when I am moving quickly (when gravityAmount is high.)
I have checked that I am not starting from within the object but I still hit the ‘Bad News’ debug line.
The problem is intermittent and I cannot replicate it everytime so the Time.deltaTime variable is possibly playing a part.
Any help would be vey welcome.
void UpdateFalling ()
{
int layerMask = 1 << 8;
//gravityAmount is a class variable (float)
gravityAmount = Mathf.Min (maxGravityAmount, gravityAmount + (Time.deltaTime * gravitySmooth));
RaycastHit hitInfo;
if (Physics.SphereCast(transform.position, 20.0f, gravityVector,
out hitInfo, gravityAmount, layerMask))
{
//Do something with hitInfo
}
else
{
//We can move to the position
transform.position = transform.position + (gravityAmount * gravityVector);
//Check we have not somehow collided.
if (Physics.CheckSphere(transform.position, 20.0f, layerMask))
{
Debug.LogError("Bad news");
}
}
}