What does this mean for me? You will always be able to play your favorite games on Kongregate. However, certain site features may suddenly stop working and leave you with a severely degraded experience.
What should I do? We strongly urge all our users to upgrade to modern browsers for a better experience and improved security.
We suggest you install the latest version of one of these browsers:
I have a Ship class that has a shipinstance and shipinstance2 nested inside of it.
function shootbullet(a, b, m, n)
var bullets = new Bullet();
bullets.x = a; //x position the bullet will spawn at
bullets.y = b; //y position the bullet will spawn at
bullets.xSpeed = m;
bullets.ySpeed = n;
bullets.rotation = this.rotation;
if (numberOfBulletsVar > 1)
shootbullet(x + shipinstance.x, y + shipinstance.y,20,20);
if (numberOfBulletsVar > 2)
shootbullet(x + shipinstance2.x, y + shipinstance2.y,20,20);
I tried that, and they spawn right at the proper spot when my ship isnt rotated, but as soon as I rotate the ship, then it spawns out of posistion. Why, and how do I fix it?
? Even if the ship is rotated, Im just setting it to the x position of the shipinstance. Thats why I dont understand. If I rotate, then the x position of shipinstance is different, so it should still spawn at it (well obviously its not, so im wrong, but I just dont understand)
Unfortunately the issue is that a child’s `x` and `y` coordinates stay the same regardless of the parent’s orientation – just a standard convention
Trigonometry should be used to calculate the global coordinates mathematically
Try this out for size. (You may need to add + or -90 after “rotation”)
xOffset = Math.sin(rotation*(Math.PI/180))*distance;
yOffset = Math.cos(rotation*(Math.PI/180))*distance;
shootbullet(x + shipinstance.x + xOffset , y + shipinstance.y - yOffset,20,20);
“distance” is however far away “shipinstance” is from the center of the parent object. So if your ship is at 20, and shipinstance is at 25, “distance” would be 5.
eh, it didnt work. Ill probably just go back to doing it the old fashioned way of having 10 bullet classes. The rotation is just making it too complicated for my first game in as3. Thanks for the attempt. When I make a top down shooter instead of astroidsesque Itll be a lot easier. Trying to compile them all into 1 clip was a great idea, but its been taking me almost a week and this rotation is still messing it up.
So I currently have it as
var pt = new Point(shipinstance.x, shipinstance.y);
but my bullet is spawning at the bottom of the screen instead of at the location of the shipintsance.
I also tried doing something like
shootbullet(x + shipinstance.pt, y + shipinstance.pt,20,20);
but with the same result. Am I doing something wrong with setting the x and y point in the localtoglobal?
Yep, you have to set your pt:Point relative to the _ship_, therefore no reference to “shipinstance.x” and “shipinstance.y”. You should have your ship drawn, say it has the cannon up front, and you want your bullets to spawn 5 pixels forwards from the center of your ship, which **is** the ship’s register point, the point around which it rotates. So, you write:
` const FIRING_POINT:Point=new Point(5,0);
shootbullet(pt, rotation); `
note that rotation has to be passed into shooting routine, otherwise you’ll have troubles when you want your ship to shoot downwards, and instead your bullets will fly say rightwards.
how would I modify my shootbullet functions x and y to just search for pt for its x and y coordinate? Im also unsure of where to add it in my Ship class. My initial thought was that it went in the Ship function, since it should only need to be loaded once, but when I do that, it says pt is an undefined property. So I stuck it in my move function which is where the enterframe event is called, and it doesnt give me the error, so I am guessing it goes there? I just want to make sure Im doing it right.