public void AddObject() { for (int i = 0; i < MaxBodies; i++) { var body = GameObject.Instantiate <CoreObject>(coreObject); body.transform.position = new Vector3(Random.Range(0, WorldSize.x), 0, Random.Range(0, WorldSize.y)); body.life = 5; body.gameObject.tag = "clone"; _csQuad.AddBody(body); _quadTree.AddBody(body); // add body to QuadTree _quadTreeBodies.Add(body); // cache bodies so we can refresh the tree in update } }
private void Update() { switch (CSType) { case CollisionSystemType.Brute: _csBrute.Step(); break; case CollisionSystemType.QuadTree: _csQuad.Step(); break; } // refresh QuadTree each frame if bodies can move _quadTree.Clear(); foreach (var b in _quadTreeBodies) { _quadTree.AddBody(b); } }
private void Start() { _quadTree = new QuadTree(new Rect(0, 0, WorldSize.x, WorldSize.y), BodiesPerNode, MaxSplits); for (int i = 0; i < MaxBodies; i++) { var body = GameObject.Instantiate <QuatTree_Cube>(DemoPhysicsBody); body.transform.position = new Vector3(Random.Range(0, WorldSize.x), 0, Random.Range(0, WorldSize.y)); _quadTree.AddBody(body); // add body to QuadTree } }
private void Start() { _quadTree = new QuadTree(new Rect(0, 0, WorldSize.x, WorldSize.y), BodiesPerNode, MaxSplits); _csQuad = new CollisionSystemQuadTree(_quadTree); for (int i = 0; i < MaxBodies; i++) { var body = GameObject.Instantiate <DemoPhysicsBody>(DemoPhysicsBody); body.transform.position = new Vector3(Random.Range(0, WorldSize.x), 0, Random.Range(0, WorldSize.y)); _csBrute.AddBody(body); // add body to CollisionSystemBrute _csQuad.AddBody(body); _quadTree.AddBody(body); // add body to QuadTree _quadTreeBodies.Add(body); // cache bodies so we can refresh the tree in update } }