Reputation: 548
I'm not sure what to do with regard to this matter, and I was hoping some of you could help.
So I have 3 arrays of projectiles, one that shoots positive on the Y-axis, one that's negative on the X-axis and one that shoots positive on the X-axis (basically, shooting in a T formation) and what I would like is to have two more sets of projectiles fire between those, so there would be 5 of them firing in the following directions: W SW S SE E
Does anyone have any ideas of how I could achieve this?
Upvotes: 1
Views: 282
Reputation: 1714
Assuming your projectiles are traveling at some velocity along the x and y axis, all you need to do is set the x and y velocity with the according cos/sin of the angle you want the projectile to travel at. Then you multiply by your speed at which you want them to travel.
Assuming you have your velocity
variable
velocity.x = Math.cos( angleInRadians ) * speed;
velocity.y = Math.sin( angleInRadians ) * speed;
Then your projectile just increments across the axis in accordance to your new velocity:
projectile.x += velocity.x;
projectile.y += velocity.y;
For your specific implementation, your angles are going to be at increments of 45 degrees. So your angleInRadians
would be 45 * Math.PI / 180
Upvotes: 1