About CollisionManagerGrid

26 views
Skip to first unread message

che...@sina.com

unread,
Aug 28, 2018, 9:29:19 AM8/28/18
to cocos2d discuss
when calculating cell_width in __init__() function of CollisionManagerGrid, it says: 

1. in objects with same size case:
    cell_width = 1.25 * object width

2. in mixed width case:
    cell_width = 1.25 * {width (object): all objects not exceptionally big}
    what does it mean??? 
    what is the value of cell_width on earth in such case?


捕获.PNG

claudio canepa

unread,
Aug 28, 2018, 10:42:40 AM8/28/18
to cocos2d discuss
Suppose you have  100 collidables with dimensions between 16 and 32, and then four big collidables  400 x 400
A good cell_width would be 1.25 * 32

A grid collision maneager works by
  - breaks the world in cells
  - each object is added to all the cells its overlap
  - when asking for collision with object A, we need to look only in the cells overlapped by A

So, if the cell size is too big they are too many objects to look in each cell.
On the other side, if cell size is too small, object A will overlap too many cells.

 If all the collidables are same size,and small relative to world size, cell_width as 1.25 * cell_width works well.

What if all the collidables are small relative to world size but not same size?. Well, 1.25 * max_width may be good enough.

What if a few big objects are added to the previous scenary ? Discard the big objects to calculate cell_width

What if theres no small size bigger than most of collidables sizes? Then probably the grid manager will not behave well, a quadtree would be better suited
   
捕获.PNG

--
You received this message because you are subscribed to the Google Groups "cocos2d discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cocos-discus...@googlegroups.com.
To post to this group, send email to cocos-...@googlegroups.com.
Visit this group at https://groups.google.com/group/cocos-discuss.
For more options, visit https://groups.google.com/d/optout.

che...@sina.com

unread,
Aug 29, 2018, 4:12:38 AM8/29/18
to cocos2d discuss
Thanks Claudio so much for your clear explanation. 

so based on my understanding,  I  guess  the statement like this would be better:
cell_width = 1.25 * max {width (object): all objects not exceptionally big} 

claudio canepa

unread,
Aug 29, 2018, 4:52:34 AM8/29/18
to cocos2d discuss
Yes, i will change the docstring, thanks.


--
Reply all
Reply to author
Forward
0 new messages