0

I'm writing my game engine using Component-Based approach and there are a 3 questions:

1) Let's imagine we have 2 objects - the orc and the bullet, who has to handle collision between them? The bullet one with it's "miniAI"?

2) The harder question is a similar to the first one - who has to handle collision .. for example.. between orc1 and orc2? which one?

3) The bullet has detected the collision and wants to destroy itself, how should it do it? Am I right if I say that destroying itself isn't good approach?

Linus Kleen
  • 33,871
  • 11
  • 91
  • 99
Alexey Teplyakov
  • 316
  • 3
  • 10
  • http://stackoverflow.com/questions/345838/ball-to-ball-collision-detection-and-handling?rq=1 – Zigma May 24 '13 at 06:38
  • You're asking too general a question. You are having trouble designing your game engine's architecture and this is not a place to learn how to do it. SO answers questions, not provides solutions. – Dariusz May 24 '13 at 06:42
  • It depends how object oriented or not you want to be. There are many ways to go about this and it's probably too broad a question. Look up [`Visitor Pattern`](https://en.wikipedia.org/wiki/Visitor_pattern) and [`Multiple Dispatch`](https://en.wikipedia.org/wiki/Multiple_dispatch) for starters. – Peter Wood May 24 '13 at 06:52
  • Well, it's my first try at creating game engine. Each object (which is just a component container) contains the set of components. For example - bullet object contains AI component, that is having 1 extra function for handle AI, including collision detection. – Alexey Teplyakov May 24 '13 at 06:54
  • First of all, you must decide much more precisely what you want. For example, if an orc cannot dodge a bullet, it usually suffices to check once whether the distance from a straight line is greater than a bounding sphere's radius, and then do the respective animations. Even if the orc can dodge and the bullet can ricochet, it is conceivable to do the same. Running a fully-fledged physics simulation with collision detection is often overkill. I wouldn't self-destruct objects. An object is owned by "someone" and whoever owns it is responsible for recycling it. – Damon May 24 '13 at 07:58

1 Answers1

1

I'd be inclined to think that neither such object should own this. It would mean each object having knowledge of every other object that is not appropriate.

I see this as a problem to be solved by the Environment which probably owns the global list of objects and hence can create and delete them.

Keith
  • 6,756
  • 19
  • 23
  • And does this Enviroment do a deferred call? Like: ai says "wow i have a collision, i have to die, enviroment, delete me please at the next frame" right? – Alexey Teplyakov May 24 '13 at 07:00