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
Add possibility to retrieve info on last collided entities #270
Add possibility to retrieve info on last collided entities #270
Conversation
Saves the first collided entity while a move check. The saved entity can then be accessed by the moving entity so it can get details on the entity it just collided with.
If A touches B, then B also touches A.
I chose to change the wording because I couldn't find a way to efficiently reset both entity and otherEntity. |
Thank you for the PR! For your information: Before reviewing this request: I've planned to introduce an event-based solution for this which would provide you with all the information about a collision that occurred. Also: It's possible that a single move collides with multiple entities within a single tick. I'll investigate the possibilities here next week when im on holiday :) Also there's a TODO in our |
Events could be a good solution. To be honest, I was too lazy to take that road.
I think it is possible, in the way I've done it, to take count of all entities colliding within a single tick. The only problem being that all entities which canCollide() will have to be checked for collision.
I saw, but did not understand the last line: |
It is now possible to retrieve information of all encountered entities after calling the move() method.
Changing back to previous code style.
It (still) wasn't possible to retrieve information from an encountered entity after the collision took place because the list was cleared on the next move() call. This is now fixed.
Hi @steffen-wilke ! |
@CalvinMT I was playing around with an implementation at the weekend. There is no state to share just yet but I think I'd like to go with the event-based approach because it seems like a cleaner solution. Your recent change from #281 is also a nice addition to this topic. I'll see what I can do this week. |
This event gets called whenever an actual collision had to be resolved during the movement of an entity. It can be subscribed to by registering an event listener via ICollisionEntity.addCollisionListener. PR #270
Saves the first collided entity while a move check.
The saved entity can then be accessed by the moving entity so it can get details on the entity it just collided with.