I'm developing a top-down shooter and I currently have a
PhysicsSystem which operates on
TransformComponents. Basically, it update each component's position based on the component's velocity, etc.
However, this only allows for one type of movement. I would like to extend this by, for example, having a projectile shoot out of a weapon and then arc in a semi-circle.
My initial solution to this was to just have a
SemiCircleProjectile component along with a
SemiCircleMovementSystem, but this did not feel generic enough. For one, it updated positions` directly rather than velocities, and also, I would have to create a new system and new component (and duplicate a lot of code) for every single different "equation" of motion.
Rather, I was wondering if there was a way to have a generic component such as
ParametricMovement, and be able to supply an equation to it, and then have a
ParametricMovementSystem be able to update that entity's position based on the equation of motion supplied.
That is, the only thing I would have to do would be to supply the equation to the component and then the generic system would process it all the same. In addition, (and I'm not sure if this is possible), I would be able to have an array of motion-modifying functions, and they would all interact and add in some way, so as to have the ability to have multiple movement-modifiers at once (for example: squiggle shot and arc-shot to make a projectile move in an arc and squiggle along the way).
My question is two-fold. One, does this sound like a good idea? And two, how might something like this be implemented? That is, should the functions set the entity's position directly? Or maybe only add to the velocity? And what sorts of parameters should this "movement equation function" take? Math is not really my strong suit. Additionally, with the "arc" example, would I be using the equation of a semi-circle: (something like
x^2 + y^2 = r^2; x >= 0) or should I be manually calculating the angles based on
cos? Should the component save the previous iteration's velocity to interpolate upon it, or recalculate it every time?
Basically, I'm not the greatest at math and I'm not exactly sure how to design a system like this. An example of how to develop something like this would be much appreciated.