Hi,
I am trying to get Physics.CheckSphere to work, but it doesn’t seem to matter what layer mask I use or what radius I use, it never registers an object with a collider. I’m just trying to test the script out right now so my code is pretty simple.
public float radiusCircle = 2400f;
public bool isSomethingThere = false;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
if (Physics.CheckSphere (transform.position, radiusCircle, 1 << 12)) {
isSomethingThere = true;
Debug.Log("There is something there");
}
}
Silly question, but are you sure there are any objects within N units of transform.position, and that the layers match? Also, anything that has anything to do with physics belongs in FixedUpdate() - though it might work in Update() 9 out of 10 times, it belongs in FixedUpdate()
– AlwaysSunnyWhenever you have a problems like this one, eliminate possibilities. Remove the '1 << 12'. Does it work? Hard-code a value for 'radiusCircle'. Note that the initialization of public variables like you do on line 1 is only used when the script is attached. After that, only the value in the Inspector matters.
– robertbu