2

I'm trying to make a shmup and trying to make a specific "bullet pattern". Basically, I have an enemy fire a number of bullets displaced around a circle. Let's say that that circle of bullets is going to the right. Next, I want the circle to collapse upon itself so I add a second impulse to the x & y velocities of the bullet. Essentially so that the shape of the bullets being fired looks something like this as it travels (I hope this shoddy symbolization makes sense):

O  o  •  o  O

That works.

Then I just want it to collapse it's vertical positioning, not horizontally so it would look like this:

O  —  O 

I can also do this. BUT, if I try to shoot this circle diagonally, or in a direction other than perfectly horizontally or vertically it breaks down a bit.

Here is the code I'm working with, the section with clusterGrowthX & Y is the part i'm having trouble with. The solution is probably staring me right in the face but I can't figure it out right now. Any questions, just ask. Thanks.

            for(var j:int = 0; j < _info.clusterAmount; j++)
            {
                var around  : Number = _info.angle - (_info.clusterRange/2) + (_info.clusterRange/_info.clusterAmount/2) + j * (_info.clusterRange/_info.clusterAmount);
                var xOff    : Number = (Math.cos(around) * _info.clusterRadius);
                var yOff    : Number = (Math.sin(around) * _info.clusterRadius);

                var bullet = new _info.bulletShape(_info);
                bullet.x = startPoint.x + xOff;
                bullet.y = startPoint.y + yOff;
                if(_info.dParent is PlayerControl)
                {
                    bullet.x += Math.cos(_info.angle) * 40;
                    bullet.y += Math.sin(_info.angle) * 40;
                }
                var sign    : Number = (_info.angle < 0) ? -1 : 1;

                trace(Math.cos(around),Math.sin(around));

                bullet.info.vx += Math.cos(around) * _info.clusterGrowthX;
                bullet.info.vy += Math.sin(around) * _info.clusterGrowthY;

                bullet.rotation = _info.angle * 180 / Math.PI;
                _info.dLevel.addChild(bullet);
            }
Evan Ward
  • 1,371
  • 2
  • 11
  • 23
  • I guess this should help you: http://math.stackexchange.com/questions/17246/is-there-a-way-to-rotate-the-graph-of-a-function (After applying the first rotation transform to follow the circling pattern, you can't rotate using sin cos anymore you have to use rotation matrices). I faced this problem: So I created a new matrix object -> translated by x|y -> rotated the matrix with built in function -> plug back x|y or you could delve into matrix calculations yourself. – chadiik Feb 27 '13 at 21:34
  • 1
    Ha ha, +1 for teaching me the term [shmup](http://en.wikipedia.org/wiki/Shoot_'em_up). I've been shmupping for almost my entire life and didn't even know it. – Sunil D. Feb 28 '13 at 02:50
  • If it is working when its perfectly horizontal, just put it in a container Sprite and rotate and move that as you need, your calculations then wont be affected by it because the bullet will always be relative to its container. – M4tchB0X3r Mar 02 '13 at 10:12

2 Answers2

1

What you need to do is have your clusterGrowth increase and decrease along an arbitrary angle.

So how do we project a point along an arbitrary angle?

var amountOfOffset:Number = 10// how far along the angle you want to go.
var angleInDegrees:Number = 45; // this is the angle you want it to expand on.
var angleInRadians:Number = angleInDegrees * 0.0174532925;
clusterGrowthX = amountOfOffset * cos(angleInRadians);
clusterGrowthY = amountOfOffset * sin(angleInRadians);

That should do you.

What you're asking is very much the same as finding a point on a circle: Find the point with radius and angle

Community
  • 1
  • 1
Plastic Sturgeon
  • 12,527
  • 4
  • 33
  • 47
0

Tween / Tweenlite library. Fixes all your problems ^_^ simple, easy, clean, optimized to heavens.

Discipol
  • 3,137
  • 4
  • 22
  • 41