Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace project collision solution with a more robust solution #147

Open
R4nKF1v3 opened this issue Jul 16, 2020 · 2 comments
Open

Replace project collision solution with a more robust solution #147

R4nKF1v3 opened this issue Jul 16, 2020 · 2 comments
Assignees
Labels
enhancement New feature or request help wanted Extra attention is needed

Comments

@R4nKF1v3
Copy link
Contributor

R4nKF1v3 commented Jul 16, 2020

This issue is mentioned as a bullet point in #68 and i'm opening it here for better isolation.

As the collision solution implemented in the project currently is not as much escalable, i'm taking a shot on it. Talking with @Stephcraft over Discord, he gave me advice on the desired implementation, using a PhysicsEngine singleton to register and handle every collision check for every non-static Collider object. The reached design is as follows:

  • Creation of a new class, PhysicsEngine, as a singleton with read-only calls across the project, with the instance that can be stored in SideScroller for update() calls.
  • Creation of a Collider abstract class which stores some rudimentary shape data, like position and rotation, bit-masking for quick collision detection, collision data, and some common collision methods. During initialization, it will register itself into the PhysicsEngine singleton, and un-register during destruction.
  • The collision calculations would be made inside each interested collider, as there could be many different collider shapes and collision logic depending of the concrete implementations.
  • Each class interested in having collision detection would need to store a concrete Collider object or list of objects, and move it along with them (as there is no common transform to move it automatically).
  • Switching the commonly used collision logic of non-static objects into these classes, and delegating the pre-calculation of collision data to the PhysicsEngine class, such as each interested class that stores a concrete Collider class can quickly access to the collision information stored in each of them (All colliders colliding and collision normals).
  • The PhysicsEngine will do some pre-calculations for each shape defining some grid-based bounding for quick collision detection (filtering the Colliders by distance). These bounds would be stored inside the Collider and recalculated each time it moves inside or outside a cell, to avoid unnecesary processing.
  • Tile-based collision data would be supported as it is now implemented, so it wouldn't be necessary to define a new Collider for each tile present in the scene.

Things left out from this refactor, left pending of implementation:

  • Other collider shapes beyond the standard RectCollider.
  • Collider shape truncation, so it isn't necessary to calculate for each of its bounds.
  • (Possibly) collision detection for rotated shapes.

Please, do tell me if i'm missing something or any suggestion, i'll be working on it shortly.

@micycle1 micycle1 added the enhancement New feature or request label Jul 17, 2020
@micycle1
Copy link
Collaborator

micycle1 commented Jul 17, 2020

I once tried to integrate the fisica library into the Project, although I came across some kind of glitch with the library and abandoned it.

It might also be worth looking at Box2D for Processing to see whether that could be integrated, before designing a new collision/physics engine in-house.

@micycle1 micycle1 added the help wanted Extra attention is needed label Jul 17, 2020
@R4nKF1v3
Copy link
Contributor Author

Thanks @micycle1 ! I'll check that library out and see if it's a viable integration (From what i've seen, it may well be what we're looking for)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants