Hi, everyone i am new to this forum aswell as pretty new to action script. But i am learning fast. I was wondering if someone who knows alot about action script could help me. I am try to make my bullets rotate to the angle my crosshair is pointed at and im having no luck.:-/
P.S : my code isnt commented sorry :shifty:
bcount = 10;
Mouse.hide();
bA = new Array();
rotate = new Array();
kess = new Array();
attachMovie("xhair", "x_mc", 5);
attachMovie("ship", "s_mc", 1);
s_mc._x = 275;
s_mc._y = 380;
function mouseM() {
mouse.hide();
x_mc._x = _xmouse;
x_mc._y = _ymouse;
}
function bulletAim(){
for (i=10; i<bcount; i++) {
cdis = _root["b_mc"+i]._x - s_mc._x;
kdis = _root["b_mc"+i]._y - s_mc._y;
kess = Math.atan2(cdis, kdis);
kess = kess*180/Math.PI;
_root["b_mc"+i]._rotation = kess
}
}
function shipMove(){
xdis = x_mc._x-s_mc._x;
ydis = x_mc._y-s_mc._y;
j = Math.atan2(ydis, xdis);
rotate = j*180/Math.PI;
s_mc._rotation = rotate;
}
function moveShip() {
if (key.isDown(key.RIGHT)) {
s_mc._x += 10;
}
if (key.isDown(key.LEFT)) {
s_mc._x -= 10;
}
}
function moveB() {
onMouseDown = function () {
attachMovie("bullet", "b"+bcount, bcount);
_root["b"+bcount]._x = s_mc._x;
_root["b"+bcount]._y = s_mc._y;
xdist = x_mc._x-s_mc._x;
ydist = x_mc._y-s_mc._y;
bA[bcount] = Math.atan2(ydist, xdist);
bcount++;
};
}
function moveBullets() {
for (i=10; i<bcount; i++) {
_root["b"+i]._x += 10*Math.cos(bA*);
_root["b"+i]._y += 10*Math.sin(bA*);
}
}
onEnterFrame = function () {
bulletAim();
shipMove();
rShip();
moveShip();
moveB();
moveBullets();
mouseM();
};