I have a submarine model that I would like to shoot torpedoes.
I want these torpedoes' initial velocity to vary with the forward velocity of its shooting submarine (so they go faster if launched off a moving sub, slower if show from a stationary sub).
I have a few requirements I'm trying to achieve:
- Torpedos despawn when they swim too far away. No need to keep them in memory if they're too far too see.
- When a torpedo is updated, and collision detection is done, there should be a way to determine who shot the torpedo, so it can be determined who to award the kill.
- Torpedos should outlive the lifecycle of its parent sub, in the case the sub is destroyed between the torpedo was shot, and the time the torpedo hits or veers too far away. (Who doesn't love double kill mechanics :D?)
- I'm working in C++, so manual memory management is a concern.
I'm debating between two approaches:
- Have subs be the owners of their torpedoes. This makes requirements 1 and 2 easy, but complicated 3.
- Have the scene be the owners of torpedoes. This makes 3 easy, but complicates 1 and 2.
This seems like it would be a common problem. What's the preferred way to do this?