- Home /
OverlapCircle performance usage
Hey!
I'll keep it simple. I use Physics2D.OverlapCircle many times with many objects for testing density so the objects don't collide with each other and create huge physics lag. But OverlapCircle already makes a lot of lag
Anything better than OverlapCircle in terms of performances? Or any other ideas?
Answer by SohailBukhari · Jul 20, 2017 at 06:14 AM
you will be using Physics2D.OverlapCircle
on all layers
instead of specific layers just collect or Filter to check objects only on specific layers.
using UnityEngine;
using System.Collections;
public class GroundHitCheck : MonoBehaviour {
//flag to find out if the object is grounded
bool isGrounded = false;
//Empty gameobject created to determine the bounds/center of the object
public Transform GroundCheck1;
//public Transform GroundCheck2; //uncomment this for OverlapArea
//The layer for which the overlap has to be detected
public LayerMask ground_layers;
//All the Physics related things to be done here
void FixedUpdate(){
//check if the empty object created overlaps with the 'ground_layers' within a radius of 1 units
isGrounded = Physics2D.OverlapCircle(GroundCheck1.position, 1, ground_layers);
Debug.Log("Grounded: "+isGrounded);
}
}
The code above is very simple, however, I will line involving the OverlapCircle function The Physics2D.OverlapCircle takes three parameters in the above function which are the empty object's position, which is (0, 0) in our case. Note that it is a Vector2. The second parameter is the radius to which the circle extends. It is set to 1 as the radius of the wheel is also 1.The third parameter is the list of layers that we should check for overlap.
Your answer
