Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I'm making a game engine in javascript for Educational purpose.
I already have the collision detection and collision response parts and are working fine, but i want to let the user define his action as a response to a collision. For example when a bullet collides with an enemy before the separation happens, i want to call a function which will kill the enemy.

I've been thinking of several methods, like:
- define a map in which the user will register a function for each collision that he wants to alter
- when a collision happens, call for each objects, in the collision, their "onCollide" function and based on the object sent as parameter a certain action will be performed.

But i don't know if these are good, or if there are other better solutions. So the question is, how do i implement this ?

share|improve this question

closed as too broad by Philipp, Seth Battin, Anko, Josh Petrie Apr 20 at 15:20

There are either too many possible answers, or good answers would be too long for this format. Please add details to narrow the answer set or to isolate an issue that can be answered in a few paragraphs. If this question can be reworded to fit the rules in the help center, please edit the question.

1  
Which solution to use is completely opinion-based. We can not help you to make that decision because we don't know your whole engine inside-out, and even when we would, the answer would still be subjective. So please make up your mind about how you want to solve this problem, and then ask about anything you want to know about implementing the solution you've chosen. –  Philipp Apr 18 at 21:12