How to efficiently implemented ball shooting?

Started by
2 comments, last by unbird 4 years, 11 months ago

So I have been trying to implement a ball shooting character in directx 12. I am having trouble figuring out how many balls should I generate when player wants to shoot and how do I manage those balls? 

Should each ball have separate world matrix? 

How do I reuse balls that have hit the target enemy or went past the viewing dimension? 

Here are ingredients I need to manage. 

1) Vertex and Index buffer entry for a geometry named “Ball”. This can be same for all balls. Need not be repeated.

2) Constant buffer entry for storing world matrix of “a” ball. For multiple ball I will have to have separate constant buffer entry.  

3) Since I am simulating physics for each item that can be rendered, I will have to have a separate physics object entry for physics engine.

For #2 Do I have to pre allocate a pre-defined maximum number of constant buffer for all balls ? Like say I can only render 20 balls on screen at max. This is possible if none of the ball hit any enemy and none of them went past the viewing screen? For other situation I can assume every balls not on screen can be reused again when player hit shooting key again. 

Is there a standard game design pattern for ball shooting? Am I looking at right direction for my attempt at designing myself? Any optimisation?

Does cuphead implemented proven pattern ?? Picture attached.

 

BFAFD6B0-DD74-44CB-9093-A8D08E08CD5A.jpeg

Advertisement

I would give all their own constant buffers. You create bullets as needed and when you are done with an object you return it to an object pool. The next time you create a bullet you check in the object pool if there are any unused bullets. If so, you use it, if not you create a new one. Each bullet will have its own transformation matrix associated with the constant buffer. The bullets can share the same index and vertex buffers.

My current game project Platform RPG

Since there's a DirectX Tool Kit for DX12, too, just use its SpriteBatch (batching is usually the answer here). It covers the administrative part and you can mostly "fire and forget" by using handy functions.

This topic is closed to new replies.

Advertisement