D
D
Di Ma2018-07-30 17:01:35
JavaScript
Di Ma, 2018-07-30 17:01:35

How, when an object moves, to transfer a record about it to the corresponding array?

Good afternoon!
I read somewhere that to improve performance, when checking for collisions of game objects, a grid is used. By coordinates, we determine in which cell of the grid the object is located, and we check for collisions only the neighbors in the cell.
But the objects themselves are not conveniently stored in a matrix. Objects are stored in one place, and only their names are in the matrix.
If the object is moving, then how to transfer its name from cell to cell? Do not check every time if he is in his cage ..

Answer the question

In order to leave comments, you need to log in

1 answer(s)
G
GreatRash, 2018-07-30
@dimentimor

1) What is needed is not a grid, but the so-called. "quadtree" or, in the language of a potential adversary - quadtree .
2) In these YouTubes of yours there is an excellent tutorial on the topic of building such a tree. Well, in general, you can google for "javascript quadtree collision detection".
3) So I even googled the implementation of this principle for you. In the demo, collisions are checked only inside the green rectangle, the rest is ignored by the engine. This is the principle of using a quadtree.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question