I want to make sure a sphere is not overlapping any other objects. When it is, I want to move it away from the overlapping collider.
My current code is:
RaycastHit intersectingHit;
while(Physics.SphereCast(hand.transform.position, handRadius, Vector3.forward, out intersectingHit, 0.01f, collisionMask)){
Vector3 direction = intersectingHit.point - hand.transform.position;
if(direction != Vector3.zero){
hand.transform.position = hand.transform.position - direction.normalized * 0.1f;
}
}
But spherecast doesn’t seem to do the trick. Any ideas?